I use Laravel and code is:
<div class="card-body">
@php($explodeFilter = [])
@if(request()->get('filterItem') != null)
@php($explodeFilter = explode(',', implode(request()->get('filterItem'))))
@endif
@foreach($filterItems as $item)
<div class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input checkFilter" @if(array_search($item->id, $explodeFilter)) checked @endif name="filter_item" value="{{ $item->id }}" id="{{ $item->id }}">
<label class="custom-control-label" for="{{ $item->id }}">{{ $item->name }}</label>
</div>
@endforeach
</div>
Url is:
/category/tv?page=1&filterItem[]=16,17,18
But result in blade is:
| url | result |
| -------- | -------------- |
| 16 | checked is false |
| 17 | checked is true |
| 18 | checked is true |
How to issue this problem and write more concisely?