You can either upgrade to Laravel 9 and use @checked
:
<input type="checkbox"
name="active"
value="active"
@checked(old('active', $user->active)) />
or do it manually in Laravel 8:
<input type="checkbox"
name="active"
value="active"
{{ old('active', $user->active) ? 'checked' : '' }} />
@geowrgetudor In my case, beacause this is an add form, not and edit one:
<input class="mt-1" type="checkbox" id="featured" name="featured" value="featured" {{ old('featured') ? 'checked' : '' }}>
You can get the old data for the checkbox as:
<input class="mt-1" type="checkbox" id="featured" name="featured" value="featured" {{ old('featured') == 'featured' ? 'checked' : '' }}>
The solution is to match the value
with the old('featured')
.
@faisal This creates another bug: the checkbox is always checked.
@ajax30 can you paste the actual code snippet.
I duplicated the solution as-is on my local project and it works as expected.
@faisal Here is the Github repo. Feel free to contribute, it is an open-source application. It's for all of us. And I believe you can bring value to it. :)
suhailparad liked this reply
@suhailparad I would love it if you did. Whatever you want to do, make a fresh branch from main and then a pull request. Thanks!
suhailparad liked this reply
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community