Thursday, April 5, 2018
[Laravel] Multiple Checkbox and Enable Checkbox
Controller
public getAccessories($request) {
$accessories = array(0=>'Charger',1=>'Battery',2=>'USB Cable',3=>'Others');
// retrieve accessories from db and convert to array
$save_accessories = unserialize($repair->accessories);
// Pass accessories to view page
return view('view', compact('$accessories', '$save_accessories'));
}
view.blade
@foreach($accessories as $i=>$accessory)
{!! Form::checkbox('accessories[]', $accessory,
in_array($accessories[$i],$save_accessories)) !!}
{!! Form::label($accessory, $accessory) !!}
<br/>
@endforeach
Subscribe to:
Posts (Atom)