Skip to content
Advertisement

Laravel put array into selectbox

I am facing some problems with my selectbox, where i will put all available categories into the

In my controller i am using this snip:

JavaScript

In my view i am trying to put all categories into the selectbox with this:

JavaScript

I could make this, but that won’t work, because Form::select has to be as an array?

JavaScript

What to do?

I have made this and it works, but it looks too ugly and not user-friendly, any suggestions?

JavaScript

var_dump:

JavaScript

Advertisement

Answer

What you need to do is give Form::select() an array of category names and their ids. If you iterate over the categories, you can aggregate these and then pass them to Form::select().

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement