I am trying to create an drop down list using blade
I have already checked this question Laravel 4 blade drop-down list class attribute
I tried this:
{{Form::select('category_id', $categories)}}
and the result is:
<select name="category_id"><option value="0">{"id":2,"name":"Apartment"}</option><option value="1">{"id":3,"name":"Car"}</option></select>
I couldn't know how to show just the name
value of the options. plus I couldn't know how to set the value of each option to its id
I know the forth parameter is the option one, and I tried to do this
{{Form::select('category_id', $categories, '', $categories)}}
but I got this exception:
htmlentities() expects parameter 1 to be string, array given (View:
please notice that the $categories
is array, each row has id
and name
Update 1
I send the value from controller to view like this
$categories = Category::All(['id', 'name']);
where Category
is a model