Search code examples
laravel-5jquery-select2laravelcollective

How to adjust jquery-select2.js code into Laravel-Collective?


I wish to make searchable box using Jquery Select2.js in Laravel-Collective code.

This is when before adjust select2.js

<!-- Customer Name Field -->
<div class="form-group col-sm-6">
    {!! Form::label('customer_name', 'Customer Name:') !!}
    {!! Form::text('customer_name', null, ['class' => 'form-control']) !!}
</div>

Also below code is working well it self as DB-Dropdown-Search-Box with select2.js code.

<div class="form-group col-sm-6" id="search_id">
    <option></option>
    @foreach($searchdata as $data)
        <option>{{$data->customer_name}}</option>
    @endforeach
</div>

Could you tell me how to adjust below searchable-box into upper Collective code?

Thank you in advanced.


Solution

  • If your $searchdata is a collection of models you can do it like this:

    <!-- Customer Name Field -->
    <div class="form-group col-sm-6">
        {!! Form::label('customer_name', 'Customer Name:') !!}
        {!! Form::select('customer_name', $searchdata->pluck('customer_name','id')->all(), null, ['class' => 'form-control']) !!}
    </div>