select option in html change to laravel collective form with for loop

user8663822 picture user8663822 · Oct 7, 2017 · Viewed 7.2k times · Source

how can i change my html form to laravel collective form

 <select style="width:50%;margin-top: 10px;" name="idw">
     <option value="0" disabled="true" selected="true">choose</option>
     @foreach($warehouse as $w)

     <option value="{{$w->id}}" name="idw" id="idw">{{$w->name}}</option>

     @endforeach
 </select>

in my collective form

 {!! Form::select('type', 
     ['Task' => $w->id  =>w-> $name ],
     null, 
     ['class' => 'form-control chosen-type', 'placeholder' => 'Please Choose']
     )!!}

i nvu use collective form before

Answer

kerrin picture kerrin · Oct 7, 2017

In your form:

<div class="form-group">
    {{ Form::label('Warehouses') }}
    {{ Form::select('warehouse', $warehouseList, null, array('class'=>'form-control', 'placeholder'=>'Please select ...')) }}
</div>

In your controller:

$warehouseList = Warehouse::all()->sortBy('name', SORT_NATURAL | SORT_FLAG_CASE)->pluck('name', 'id');