Reputation: 4232
Laravel 5.2: How to read and show the checked item(s) of a group of checkbox in edit page?
For example:
view:
{!! Form::open(array('url' => 'foo/bar')) !!}
<div class="checkbox">
<label class="checkbox-inline">
<input type="checkbox" id="checkbox1" name="checkbox[]" value="1">apple
</label>
<label class="checkbox-inline">
<input type="checkbox" id="checkbox2" name="checkbox[]" value="2">pear
</label>
<label class="checkbox-inline">
<input type="checkbox" id="checkbox3" name="checkbox[]" value="3">grape
</label>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
{!! Form::close() !!}
controller:
$checkboxes = $request->input('checkbox');
I turn it into JSON with json_encode() and save them all in one column.After this, when I access the edit page,how to read and show them? That being said, the checked items will be checked,and the not checked items will not be checked in edit page.
Upvotes: 2
Views: 940
Reputation: 25221
<input type="checkbox" id="checkbox1" name="checkbox[]" value="1" {{in_array($checkboxes, 1) ? 'checked' : ''}}>
Upvotes: 1