Dropdown in laravel

Published 6 months ago by anp24

How do I fill the drop down through controller and the drop down is placed in blade.php. Drop down must be multi select. Also only server side php mvc laravel code is required.

anp24

Please reply as it is urgent

Dry7
Dry7
6 months ago (151,680 XP)

@anp24 Controller

class TestController extends Controller
{
    public function index()
    {
        return view('form')
            ->with('options', [
                'First',
                'Second',
                'Third'
            ]);
//        return view('form')->with('options', YouModel::all());
    }
}

/resources/views/form.blade.php

<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.6-rc.0/css/select2.min.css" rel="stylesheet" />
<script src="https://code.jquery.com/jquery-3.2.1.min.js">
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.6-rc.0/js/select2.min.js"></script>
<script>
  $(document).ready(function() {
    $('select').select2();
});
</script>

<select name="test" multiple="multiple">
    @foreach($options as $option)
        <option value="{{ $option }}">{{ $option }}</option>
    @endforeach
</select>

Please sign in or create an account to participate in this conversation.