Reputation: 481
I'm trying to access the 'cat' value in my array below, coming from my controller.
If I dump $tempCategories it shows the array correctly but my html is showing nothing for some reason.
Am I not accessing the element correctly?
I expect to see
Wood
Metal
controller.php
$tempCategories = array(
0 => array(
'cat' => 'Wood'
),
1 => array(
'cat' => 'Metal'
),
);
blade.php
@foreach($tempCategories as $cat)
<h5>{{$cat->cat}}</h5>
@endforeach
Upvotes: 0
Views: 2631
Reputation: 39
If you want to access it with arrow operator - convert your array to object or collection first (in your controller)
$object = (object) $array;
Or
$collection = collect($array);
Upvotes: 0
Reputation: 15131
You are trying to access an array as object
Replace
<h5>{{$cat->cat}}</h5>
With
<h5>{{$cat['cat']}}</h5>
Upvotes: 3