Level 3
I think you should change
{{ (old('available') == 'unknown') ? 'checked' : ''}}
to
{{ (old('available', 'unknown') == 'unknown') ? 'checked' : ''}}
Now, you pass a default value for "available" if the old value is not set.
1 like
I'm using old() to retain radio button selection after form validation error in Laravel, but I also want to make option "Unknown" selected by default.
The form element looks like this:
<label for="description">Product Available</label><br/>
<label class="radio-inline"><input type="radio" name="available" id="available" value="yes" {{ (old('available') == 'yes') ? 'checked' : ''}}>Yes</label>
<label class="radio-inline"><input type="radio" name="available" id="available" value="no" {{ (old('available') == 'no') ? 'checked' : ''}}> No</label>
<label class="radio-inline"><input type="radio" name="available" id="available" value="unknown" {{ (old('available') == 'unknown') ? 'checked' : ''}}> Unknown</label>
This works fine, but I need the "Unknown" option to be set by default when opening form without overriding "old()" data.
How can I do this?
I think you should change
{{ (old('available') == 'unknown') ? 'checked' : ''}}
to
{{ (old('available', 'unknown') == 'unknown') ? 'checked' : ''}}
Now, you pass a default value for "available" if the old value is not set.
Please or to participate in this conversation.