<input
type="checkbox"
name="bidang[]"
value="Pendidikan"
{{ (is_array(old('bidang')) && in_array('Pendidikan', old('bidang'))) ? ' checked' : '' }}
/>
show if checkbox is checked or unchecked in edit view
how to show checked unchecked in multiple checkbox laravel edit blade view
ps: array data
edit blade view :
<form method="POST" action="{{url('user/rencana-kerjasama/edit')}}" enctype="multipart/form-data" class="form-horizontal">
{{ csrf_field() }}
<div class='col-md-6'>
<div class="checkbox">
<label>
<input type="checkbox" name="bidang[]" value="Pendidikan" @if(is_array(old('bidang')) && in_array('Pendidikan', old('bidang'))) checked @endif>Pendidikan
</label>
</div>
<div class="checkbox">
<label>
<input type="checkbox" name="bidang[]" value="Penelitian" > Penelitian
</label>
</div>
<div class="checkbox">
<label>
<input type="checkbox" name="bidang[]" value="Pengabdian Masyarakat"> Pengabdian Masyarakat
</label>
</div>
</div>
</form>
controller :
public function edit($id)
{
$title = $this->title;
$data = RencanaKerjasama::find($id);
return view('user.' . $title . '.edit', compact('title', 'data'));
}
i use this but not work
@if(is_array(old('bidang')) && in_array('Pendidikan', old('bidang'))) checked @endif
Or you trying to get old value if edit fails or display the value from database when edit page loads.
If the second case, you have to actually get the data yourself from the database, example for a single checkbox:
<input type="checkbox" name="adopted" id="adopted" value="1" {{ ($cat->adopted == 1 ? ' checked' : '') }}
In other words do an if like I showed to see if the value was a 0 or a 1. In your case you have to loop since it's an array.
I usually like individual checkboxes to avoid having to loop over them.
https://laracasts.com/discuss/channels/general-discussion/blade-checkbox-and-eloquent
Please or to participate in this conversation.