It is good practice to show the old values of a form when an error occurs after submitting the form. But it is a little bit difficult to show old values in the multi select dropdown form and an input form which is an array.

In this tutorial, we will see old value in multiple select option in laravel blade tutorial. So you will see laravel old value array from multi select input box.

laravel-multi-select-old-value-selected

Let's see the example code:

<form action="{{ route('product.search') }}" method="post">
  @csrf
    <div class="row">
      <div class="col-md-10 form-group">
        <label for="">Category</label>
        <select name="category_id[]" class="form-control" multiple>
          @foreach (\App\Models\Category::all() as $item)
           @if (old('category_id'))
             <option value="{{ $item->id }}" {{ in_array($item->id, old('category_id')) ? 'selected' : '' }}>{{ $item->name }}</option>   
           @else
             <option value="{{ $item->id }}">{{ $item->name }}</option>
           @endif 
          @endforeach
        </select>
       </div>
      <div class="col-md-2 form-group" style="margin-top:25px;">
        <input type="submit" class="btn btn-primary" value="Filter">
       </div>
    </div>
 </form>

 

Read also: Laravel 10 Custom Validation Rule Example

 

Conclusion

Now we know old value in multiple select option in laravel blade. Now we know how to display multiple selected old value after submit form. Hope this laravel old value array tutorial help you to show old value in multi select or array type input form.