laravel dropdown from database

Posted by w3diy - 2 months ago

laravel dropdown from database : Laravel Select Dropdown From Database Example

/**

* Show records

*

* @return \Illuminate\Http\Response

*/



public function dropDownShow(Request $request)

{

   $items = Item::pluck('name', 'id');

   $selectedID = 2;

   return view('items.edit', compact('id', 'items'));

}

Example 1 : Using Form

<div class="form-group">
    {!! Form::Label('item', 'Item:') !!}
    {!! Form::select('item_id', $items, $selectedID, ['class' => 'form-control']) !!}
</div>

Example 2 : Without Using Form

<select class="form-control" name="product_id">
    <option>Select Item</option>
    @foreach ($items as $key => $value)
        <option value="{{ $key }}" {{ ( $key == $selectedID) ? 'selected' : '' }}> 
            {{ $value }} 
        </option>
    @endforeach    
</select>