0

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

2 Answers 2

3

You are trying to access an array as object

Replace

<h5>{{$cat->cat}}</h5>

With

<h5>{{$cat['cat']}}</h5>
Sign up to request clarification or add additional context in comments.

Comments

0

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);

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.