You have to "test" if it's true or false, 0 or 1. If true or 1 check it in code.
Apr 15, 2017
6
Level 2
Getting a checkbox checked
I have group of checkbox which I add to database as an array [1,2,3] everything going OK when I adding it but what about retrieve it from the database to edit.
here is my controller
public function edit($id)
{
$temp = Template::query()->findOrFail($id);
$extra = TempExtraService::all();
return view('admin.templates.tempDetails.edit', compact('temp', 'extra'));
}
and here is my view
<div class="form-group">
{!! Form::label('extra_services', 'Add extra services') !!}
<div class="form-group">
@foreach($extra as $ext)
<div class="checkbox">
<label>
{!! Form::hidden('extra_services[]', 0) !!}
{!! Form::checkbox('extra_services[]', $ext->id, $temp->extra_services, ['class' => 'checkbox']) !!}
{!! $ext->title !!}
</label>
</div>
@endforeach
</div>
</div>
I get all the checkbox s checked even if they are not even review the table after editing
got something like this 0,1,0,2,0
Please or to participate in this conversation.