I am trying to get array of checkbox from database and then explode them to check each checkbox dynamically but the results
getting all checkbox not checked, however if I try {!! diploma->courses !!} the results will be (2,3,7).
Any help please what I am missing here.
Here is the controller
public function edit( $id ) {
$diploma = Diploma::query()->find( $id );
$courseCategories = CourseCategory::all();
return view( 'admin.diploma.edit', compact( 'diploma', 'courseCategories' ) );
}
and here is where it should explode the checkbox
<div class="box-group" id="accordion">
<?php $i = 1; ?>
@foreach($courseCategories as $courseCategory)
<?php $i ++ ?>
<div class="panel box box-primary">
<div class="box-header with-border">
<h4 class="box-title">
<a data-toggle="collapse" data-parent="#accordion"
href="#collapse{!! $i !!}"
aria-expanded="false" class="collapsed">
{!! $courseCategory->title !!}
</a>
</h4>
</div>
<div id="collapse{!! $i !!}" class="panel-collapse collapse" aria-expanded="false"
style="height: 0;">
<div class="box-body">
<div class="form-group">
@foreach($courseCategory->courseItem as $course)
<div class="checkbox">
<label>
<input type="checkbox" name="courses[]"
value="{!! $course->id !!}"
{!! in_array($course->id, explode(",", $diploma->coueses)) ? 'checked' : '' !!} >
{!! $course->title !!}
</label>
</div>
@endforeach
</div>
</div>
</div>
</div>
@endforeach
</div>
Aucun commentaire:
Enregistrer un commentaire