Ad

How To Convert Select Box Html To Form Html Collactive

- 1 answer

Hi i have this in my controller

$listPatient = Patient::get();

    return view('backend.consultations.create')->with([
        'patient' => $this->patient,
        'patient_id' =>$this->patient_id,
        'listPatient' => $listPatient,
        ]);

and in my view i have

<div class="form-group">

    <div class="col-md-2">
        List clients
    </div>
    <div class="col-lg-10">

         <select name="patient_id">
            <option value="0">Veillier séléctionner un patien </option>
            @foreach($listPatient as $key)
              <option value="{{$key->id}}">{{$key->nom_patient}} {{$key->prenom_patient}}</option>
            @endforeach
        </select> 
    </div><!--col-lg-10-->
</div><!--form control-->

and it work fine,i want to use Form::select but it doesn't work can anyone help me please

Ad

Answer

In your controller you would want the following to fetch $listPatient

$listPatient = Patient::lists("nom_patient","id")->toArray();

and in your view you would want

{!! Form::select('patient_id', [0 => 'Veillier séléctionner un patien'] + $listPatient, null) !!}
Ad
source: stackoverflow.com
Ad