I'm currently learning laravel and creating my first form. Everything is awesome until I want to use {{ old('') }} helper in my blade file for radio buttons. I'm not sure how to go about doing it properly, and I can't seem to find much info on here about it either.
The code I have is as follows:
<div class="form-group">
<label for="geckoHatchling">Gecko Hatchling?</label>
<div class="radio">
<label>
<input type="radio" name="geckoHatchling" id="geckoHatchlingYes" value="1">
Yes
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="geckoHatchling" id="geckoHatchlingNo" value="0" checked>
No
</label>
</div>
</div>
I think the following is a little bit cleaner:
<input type="radio" name="geckoHatchling" value="1" @if(old('geckoHatchling')) checked @endif>
<input type="radio" name="geckoHatchling" value="0" @if(!old('geckoHatchling')) checked @endif>
@if
is checking the truthiness of the old value and outputting checked
in either case.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With