Search code examples
laravellaravelcollective

how to create optgroup with laravel collective?


I need to create a optgroupt with laravel collective.

Below is my current code:

<select id="cmb" name="cmb">
   <option></option>
   @foreach($sedeCaptura as $i)
      <optgroup label="SEDE - {{ $i["SedeCaptura"] }}">
         <option value="{!! $i["SedeCaptura"] !!}" >
            {!! $i["IdField"].' - '.$i["DescriptionField"].' - ('.$i["TotalField"].')' !!}
         </option>
      </optgroup>
   @endforeach
</select>

How do I recreate this code with laravel collective?


Solution

  • A simple multidimensional array should do the job as specified in the documentation you can pass a key for the label and an array of key => value pair as follow:

    echo Form::select('animal',[
        'Cats' => ['leopard' => 'Leopard'],
        'Dogs' => ['spaniel' => 'Spaniel'],
    ]);