0

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.

JsWizard
  • 1,663
  • 3
  • 21
  • 48

1 Answers1

1

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>
Andriy Lozynskiy
  • 2,444
  • 2
  • 17
  • 35
  • Thank you very much, your code is more effective than select2.js in Laravel. :) Could you tell me where can I see more information about to use this method? and how to adjust text writing for search in this box? – JsWizard Oct 07 '17 at 22:04