am trying to check checkbox after i search something. i did something like this
@if (request()->discount)
checked
@endif
and it's working but in categories if i check one of categories and filter by it then all categories are checked.
<input id="subCats-{{$s->id}}" name="category[]" type="checkbox" value="{{ $s->id }}"
@if (request()->category)
checked
@endif
>
and am having problem with
<input type="checkbox" name="level" value="0" id="lvl-0"
@if (request()->level == 0)
checked
@endif
it's always is checked because if i don't requests its null and it's thinks that its 0 i trying (request()->level === 0) but it's still don't works.
CodePudding user response:
<input id="subCats-{{$s->id}}" name="category[]" type="checkbox" value="{{ $s->id }}"
@if (request()->category != "" && in_array($s->id,explode(','request()->category)))
checked
@endif
>
if you are padding multiple category comma separated (,)
<input type="checkbox" name="level" value="0" id="lvl-0" @isset(request()->level) checked @endif>
CodePudding user response:
<input id="subCats-{{$s->id}}" name="category[]" type="checkbox" value="{{ $s->id }}"
@if (request()->category != "" && in_array($s->id,request()->category))
checked
@endif
>
Use this instead