I am getting an array of products from my database and need to know how to list them in a drop down in a form within my blade file.
Currently, the array I'm using looks like this:
$products = [
{
id:1,
name:product_1,
qty:5,
price:3.99
},
{
id:2,
name:product_2,
qty:5,
price:5.99
}
{
id:3,
name:product_3,
qty:20,
price:10.99
}
{
id:4,
name:product_4,
qty:10,
price:3.99
}
]
and my form tags lok like this
{!! Form::select('product', $products); !!}
How can i get it to only display the name from the object and also when i submit to using the ID in stead of the drop down index.
If you need any more info i am happy to supply it :)
Thanks in advance.
$products - must be collection then
{!! Form::select('product', $products->pluck('name','id')) !!}
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community