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

ddiskandar liked this thread

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 2 years 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 2 years 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 2 years 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 2 years ago.

suhailparad liked this reply

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!

suhailparad liked this reply

1

@ajax30 I will do that.

0

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

suhailparad liked this reply

1

@ajax30 i will do that today

0

@suhailparad Please help me with this question. Thanks!

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Razvan ajax30 Joined 2 Oct 2021

Moderators

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

Your logo here?

Laravel.io

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

© 2024 Laravel.io - All rights reserved.