Support the ongoing development of Laravel.io →
Blade Validation
Last updated by @ajax30 1 month ago.
1

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' : '' }} />
Last updated by @geowrgetudor 3 months ago.
0

@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' : '' }}>
0

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').

0

@faisal This creates another bug: the checkbox is always checked.

Last updated by @ajax30 3 months ago.
0

@ajax30 can you paste the actual code snippet.

I duplicated the solution as-is on my local project and it works as expected.

Last updated by @faisal 3 months ago.
0

@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. :)

Last updated by @ajax30 3 months ago.
1

@ajax30 I would like to contribute

0

@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!

1

@suhailparad I have not seen any new pull reqests. :)

1

Sign in to participate in this thread!

Full Stack Europe

Your banner here too?

Razvan Razvan ajax30 Joined 2 Oct 2021

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

The Laravel portal for problem solving, knowledge sharing and community building.

© 2022 Laravel.io - All rights reserved.