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);
The pluck helper method is used to retrieve a list of specific values from a given $array. It is most useful when used against arrays of objects, but will also work with arrays just as well. You might often run into a situation where you have to extract certain value from a collection.
log() method returns the natural logarithm (base e) of a double value as a parameter. There are various cases : If the argument is NaN or less than zero, then the result is NaN. If the argument is positive infinity, then the result is positive infinity.
Laravel Pluck() is a Laravel Collections method used to extract certain values from the collection. You might often would want to extract certain data from the collection i.e Eloquent collection.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With