When it's checked and the validation fails with other fields in the form, `{{ old('first_name') }} works but it doesn't work for checkbox.
How can I make it auto check the checkbox if it was checked and how can I make the checkbox auto check if in database, it has been checked (say when the user is editing his account info and his "use_signature" has been checked – I want to show that the checkbox has been checked automatically).
If this is an edit form pass the value from the model as the second parameter for the old function.
The hidden input is a trick I like to use to make handling checkboxes easier.
Normally for a checkbox the value is submitted if the box is checked and nothing at all is submitted if it is not.
This makes you have to use things like isset or !emptywhen looking at checkbox values as the key wont exist in the request if the box wasn't checked.
With the hidden input the key will always be submitted with either 1 if checked or 0 if not checked.
What do your controllers look like that you guys feel the need to add hidden input fields? To me, it just looks like you are unnecessarily complicating things..
But if I pass the second parameter in the old function, I will get an error when using the same form for "creating" as it will only work for "editing"
In the controller that shows the add form just do a new ModelName() to create a blank instance of the model and pass it to the view. Then the view should look the same for the add and the edit form.
<input type="checkbox" name="accepted_terms_cond" value="1" {{ old('accepted_terms_cond') ? 'checked' : null }}> I have read and accept the terms and conditions.