jeudi 6 décembre 2018

Laravel 5.7 fill data direct from database to select input

I want to get direct data in master table with format array($key => $value) :

in controller:

$result = array();
$color_list = Master::whereRaw("type = 'color'")->get();

// format data for select input
foreach ($color_list as $value) {
     $result[$value->id] = $value->name;
}

return view('backend.product.create', compact('result')

in View:

{!! Form::select('color', $result) !!}

Purpose: Do not use foreach to build data for the selected input

i find a code:

$color_list = Master::lists('id', 'name');

but it not work on Laravel 5.7

Can anyone please help?



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2zJhw47
via IFTTT

Aucun commentaire:

Enregistrer un commentaire