Reputation: 1711
I can take the list using
$specialities = Speciality::pluck('name','id')
Why isn't the following code working? What could be an alternative?
I am returning this array by ajax to form a select box. So I thought pluck
(list in laravel 4+) would be the right choice.
$specialities = Speciality::pluck('name','id')->where('role_id',$request->roleid);
Upvotes: 33
Views: 42761
Reputation: 1711
I found the mistake. I should use pluck with where condition like below.
$specialities = Speciality::where('role_id',$request->roleid)->pluck('name','id');
Pluck won't filter anything, but it gives only what needed. So filtering has to be done before that.
Upvotes: 74