In my edit.blade, I would like to show categories that were checked before by user + user can check new categories. So if a validation error occurred, the newly checked categories do not become unchecked.
This is what I have now:
@foreach($categories as $category)
<input type="checkbox" id="category_id" name="category_id[]" value="{{ $category->id }}"
{{ $category->posts->contains($post->id) ? 'checked' : '' }}
@if (old('category')==$category->id) ? 'checked' : '' @endif>
<label for="{{$category->id}}"> {{$category->category_name}}</label>
@endforeach
How can I do it?