Menu

Populating a dropdown menu with database results in Laravel with empty option in Form::select with lists()

Written by

In order to populate a dropdown menu with all the records from the Category Model, you can do the following, in your blade (view) file:

{{ Form::select('drpCatg', \App\Category::lists('category_name', 'id')) }}

If you want to add empty or ‘— Select Category —‘ option first, you can do the following, in your blade (view) file:

If you are trying to following code and getting error “Unsupported operand type”

{{ Form::select('drpCatg', ['0' => 'Select'] + \App\Category::lists('category_name', 'id')) }}

Replace above code with

{{ Form::select('drpCatg', ['0' => 'Select'] + \App\Category::lists('category_name', 'id')->all() }}

 

Article Categories:
Laravel

Comments are closed.

Shares