Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show old data of `select` element in Laravel?

Tags:

html

laravel-5

How to show old data of select element in Laravel?

Data can be shown in input like this:

<input id="name" name="name" class="form-control" type="text" value="{{ old('name', $user->name) }}">

when the element is select,how to show the old data?

<select class="form-control" name="gender">
    <option value="male">male</option>
    <option value="female">female</option>
</select>
like image 434
zwl1619 Avatar asked Nov 21 '25 09:11

zwl1619


1 Answers

<select class="form-control" name="gender">
    <option value="male" @if (old('gender') == 'male') selected="selected" @endif>male</option>
    <option value="female" @if (old('gender') == 'female') selected="selected" @endif>female</option>
</select>
like image 175
HTMHell Avatar answered Nov 24 '25 00:11

HTMHell



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!