I'm quite new to PHP Blade/Laravel and I'm trying to display an array, which is inside an variable, as HTML.
So I got an variable named $products
and first of all I did this:
{{ print_r($products) }}
This gave me:
Array
(
[0] => Array
(
[title] => Belt
[image] => img/products/belt.jpg
[price] => 79.00
[specialPrice] =>
)
[1] => Array
(
[title] => Hat
[image] => img/products/hat.jpg
[price] => 89.00
[specialPrice] => 69.00
)
[2] => Array
(
[title] => Bag
[image] => img/products/bag.jpg
[price] => 99.00
[specialPrice] => 59.00
)
[3] => Array
(
[title] => Scarf
[image] => img/products/scarf.jpg
[price] => 119.00
[specialPrice] =>
)
)
1
So, I want to display this Array as HTML. I tried this:
@foreach($products as $key => $item)
<p>{{@item->title}}</p>
@endforeach
But that didnt work. What am I doing wrong?
Try this :
@foreach($products as $product)
<p>{{$product->title}}</p>
@endforeach
or this
@foreach($products as $product)
<p>{{$product[title]}}</p>
@endforeach