How to Get the Old Value of the Select in Laravel
In this lesson, we will see how to get the old value of the select when editing in Laravel, this approach will make the user see his previously selected option when updating the form.
Display the old value of the select when editing records in Laravel
To do that let's assume that we are updating a post with a select element that contains the categories see the example below:
<div class="mb-3"> <label for="category_id" class="form-label">Category*</label> <select class="form-select" name="category_id" id="category_id" > <option selected disabled value="">Select one category</option> @foreach ($categories as $category) <option value="{{$category->id}}" @selected(old('category_id',$post->category_id) == $category->id) > {{$category->name}} </option> @endforeach </select></div>