In my form I want the checkboxes to keep their states (checked or unchecked) after a validation error. This is what I have so far:
<input type="checkbox" id="delete-user" class="form-check-input" data-data-section="users" name="permissions[]" value="delete-user" {{ (is_array(old('permissions')) && in_array(1, old('permissions'))) ? ' checked' : '' }}>
But it looks that the old() function doesn't work. I also tried:
old('permissions.'.$key)
where $key is the checkbox array index but it doesn't work neither.
Any idea ?
CodePudding user response:
I think you are an invalid value pass in the in_array function
Try this:
value="delete-user" {{ (is_array(old('permissions')) && in_array('delete-user', old('permissions'))) ? ' checked' : '' }}>