I have filtered data from the database to match some array values, which were taken from the select picker. When I was tried to rest select picker, it not working, and the filter data not listed properly. I have tried with this code.
HTML:
<select class="form-control selectpicker" id="filter_category" multiple data-live-search="true" title="Select Category"> <option value=""> Select Category</option> @if(!empty($Category)) @foreach($Category as $data) <option value="{{$data['id']}}">{{$data['name']}}</option> @endforeach @endif </select>
JS:
$("#filter_category").val('').selectpicker("refresh");
Controller:
if(!empty($request->filter_category)) { $query->whereIn('id', $request->filter_category); }
Remove this line from select:
<option value=""> Select Category</option>
Try with this code.
<select class="form-control selectpicker" id="filter_category" multiple data-live-search="true" title="Select Category"> @if(!empty($Category)) @foreach($Category as $data) <option value="{{$data['id']}}">{{$data['name']}}</option> @endforeach @endif </select>
Apply this code in the controller:
if(!empty($request->filter_category)) { if(sizeof($request->filter_category) > 0) { $query->whereIn('id', $request->filter_category); } }
Hope it will be helpful for you.
Question and answer is powered by AnsPress.io