Search code examples
phplaravelselectlaravel-5bootstrap-selectpicker

How to get data from database and show it in selectpicker in Laravel?


I have a form page and detail page. When I input and submit data from form page, it will redirect to detail page. And I don't know how to show the data which I submitted into a selectpicker? It showed, but double like in the image below..

<select id="set1" name="res_destination" class="selectpicker form-control edit" data-live-search="true" style="width:100%" disabled required>
   <option>{{ $data[0]->DESTINATION }}</option>
   <option></option>
   @foreach($destination as $getData)
      <option value="{{$getData->REF_TEXT}}"> {{$getData->REF_TEXT}} </option>
   @endforeach               
</select>

enter image description here


Solution

  • use selected to make a dropdown value selected.

    <select id="set1" name="res_destination" class="selectpicker form-control edit" data-live-search="true" style="width:100%" disabled required>
      @foreach($destination as $getData)
         <option value="{{$getData->REF_TEXT}}" @if($data[0]->DESTINATION==$getData->REF_TEXT) selected @endif> {{$getData->REF_TEXT}} </option>
      @endforeach