In this tutorial, we will learn how to create a multi select dropdown select box in laravel blade and then how to show the option selected. So you will learn laravel select option selected from database. I will use select2 for this dropdown so that we can select multiple options. In this how to display selected multiple dropdown values in edit page laravel tutorial, we will fecth data from server and we will make it selected.

For that, I will create two arrays, one is for listing and another is for showing selected. So let's see the example code of old value in multiple select option in laravel blade:

laravel-select-box-selected-by-old-values

So let's see the source code of option value selected in laravel blade:

@extends('layouts.app')

@push('style')
<link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css" rel="stylesheet" />
<style>
    span.select2.select2-container.select2-container--classic{
        width: 100% !important;
    }
</style>
@endpush

@section('content')
<div class="container">
    <div class="row justify-content-center">
        <div class="col-md-8">
            <div class="card">
                <div class="card-header" style="background: gray; color:#f1f7fa; font-weight:bold;">
                    Laravel 9 Select2 Multi Select Dropdown With Selected Example  -  Laravelia
                </div>
                 <div class="card-body">
                    @php
                        $languages = [
                            'PHP',
                            'Python',
                            'C#',
                            'C',
                            'C++',
                            'Ruby',
                            'Perl'
                        ];

                        $selected = [
                            'PHP',
                            'Python',
                        ];
                    @endphp                    
                    <form class="w-px-500 p-3 p-md-3" action="{{ route('user.store') }}" method="post" enctype="multipart/form-data">
                        @csrf
                        <div class="row mb-3">
                            <label class="col-sm-3 col-form-label">Framework</label>
                            <div class="col-sm-9 mt-3">
                                <select class="js-example-basic-single" multiple name="Framework[]">
                                    @foreach ($languages as $item)
                                        <option value="{{ $item }}"
                                            {{ in_array($item,$selected) ? 'selected' : '' }}>
                                            {{ $item }}
                                        </option>
                                    @endforeach
                                </select>
                            </div>
                        </div>
                        <div class="row mb-3">
                            <label class="col-sm-3 col-form-label"></label>
                            <div class="col-sm-9">
                                <button type="submit" class="btn btn-success btn-block text-white">Submit</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection

@push('script')
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script>
<script>
    $('.js-example-basic-single').select2({
        theme: "classic",
        placeholder: 'Search Language',
    });
</script>
@endpush

 

Read also: Select2 Array - Dropdown Search In Laravel Application

 

Conclusion

Hope this old value in multiple select option in laravel blade tutorial will help. After completing this option value selected in laravel blade tutorial, your concept will be clear about laravel 9 select option selected from database. Hope this laravel select option selected from database tutorial will clear your concept about laravel select box selected.