Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to keep old value in select option when updated the form in laravel?

How to keep old value in select option when I updated the form?

Form:

<select class="form-select" name="slug" id="slug" value="{{$project->slug ?? '' }}">
<option value="">Select Category </option>
<option value="commercial">commercial</option>
</select>

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can use old() like this

<select class="form-select" name="slug" id="slug">
    <option value="commercial" {{ old('slug', $project->slug) == 'commercial' ? 'selected' : '' }}>Commercial</option>
    <option value="another" {{ old('slug', $project->slug) == 'another' ? 'selected' : '' }}>Another</option>
    <option value="anotherrr" {{ old('slug', $project->slug) == 'anotherrr' ? 'selected' : '' }}>Anotherrr</option>
</select>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading