Laravel 5 - Old Data on multiple checkboxes -
i have lot of checkboxes take following form in template
<div class="col-md-6 checkbox checkbox-danger"> {!! form::checkbox('testingoptions[]', 'checkbox a', null, ['class' => 'styled', 'id' => 'checkbox1']) !!} <label for="checkbox1"> checkbox </label> </div> <div class="col-md-6 checkbox checkbox-danger"> {!! form::checkbox('testingoptions[]', 'checkbox b', null, ['class' => 'styled', 'id' => 'checkbox2']) !!} <label for="checkbox2"> checkbox b </label> </div>
so selected options saved testingoptions[].
in controller, input, , implode of choices single string
$testingoptions = input::get('testingoptions'); $testingoptions = implode('&&&', $testingoptions);
in database, end this
checkbox a&&&checkbox b
this fine. edit controller, doing following
$selectedoptions = $project->something->testing; if($selectedoptions != "") { $selectedoptions = explode('&&&', $selectedoptions); return view::make('something.edit', compact('project', 'selectedoptions')); }
with done, in edit template, if output selectedoptions have this
array:2 [▼ 0 => "checkbox a" 1 => "checkbox b" ]
so knowing on edit page have
<div class="col-md-6 checkbox checkbox-danger"> {!! form::checkbox('testingoptions[]', 'checkbox a', null, ['class' => 'styled', 'id' => 'checkbox1']) !!} <label for="checkbox1"> checkbox </label> </div> <div class="col-md-6 checkbox checkbox-danger"> {!! form::checkbox('testingoptions[]', 'checkbox b', null, ['class' => 'styled', 'id' => 'checkbox2']) !!} <label for="checkbox2"> checkbox b </label> </div>
is there way use variable array of selected options pre-select matches within form?
thanks
i managed solve doing
{!! form::checkbox('testingoptions[]', 'checkbox a', in_array('checkbox a', $testingoptions), ['class' => 'styled', 'id' => 'checkbox1']) !!} {!! form::checkbox('testingoptions[]', 'checkbox b', in_array('checkbox b', $testingoptions), ['class' => 'styled', 'id' => 'checkbox1']) !!}
Comments
Post a Comment