Home > database >  How to getting selected option value with another table in laravel?
How to getting selected option value with another table in laravel?

Time:01-03

<select  id="exampleSelectRounded0" name="kode_poli">
@foreach ($polikliniks as $poliklinik)
<option value="{{$poliklinik->id}}">{{$poliklinik->kode_poli}} | {{$poliklinik->nama_poli}}</option>
@endforeach
</select>

My select option value will return a first id of poliklinik table

How to set select option 'selected' with another value in poliklinik table with my selected value when i insert before?

CodePudding user response:

You will need to write an option with the selected id as the value and selected name in between the option tag

<select  id="exampleSelectRounded0" name="kode_poli">
<option value="{{$selected->id}}">{{$selected->kode_poli}}</option>
@foreach ($polikliniks as $poliklinik)
<option value="{{$poliklinik->id}}">{{$poliklinik->kode_poli}}</option>
@endforeach
</select>

Note: substitute the selected with the model you used in saving it

  • Related