I'm trying to use the PLUCK method to display two columns of a table when selecting them
$driverItems = Driver::pluck('driverName','id')->toArray();
On
You can do it by pluck() and use Form Facade in the view file.
use Illuminate\Support\Arr;
$data = Driver::get();
$data= Arr::pluck($data, 'driverName','id');
In view file,to create dropdown use below code:
{{ Form::select('element_name',$data,['class'=>'form-control','id'=>'driver_list','placeholder'=>'-- Select --']) }}
It will create dropdown with place holder.
pluck()will always create a single collection array (for multiple column pluck, it will be single object). Such as, this query output might look like:You may try like following:
This will output like:
and for dropdown you can show it like: