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.


Let's see the example code:

<form action="{{ route('') }}" method="post">
    <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>   
             <option value="{{ $item->id }}">{{ $item->name }}</option>
      <div class="col-md-2 form-group" style="margin-top:25px;">
        <input type="submit" class="btn btn-primary" value="Filter">


Read also: Laravel 10 Custom Validation Rule Example



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.