Thomas Vercamer
Thomas Vercamer

Reputation: 57

Laravel 5 - returns array, but no array[key]

I have an array that I return from my controller to my view.
If I enter the following:

{{ $subpage["name"] }}

Laravel throws an error (undefinded index: name).
However, when I use:

{{ $subpage }}

I get this result:

[{"id":1,"name":"Additional Information","category":"General","link":"additionalinfo","created_at":"-0001-11-30 00:00:00","updated_at":"-0001-11-30 00:00:00"}]

So I really don't see what I'm doing wrong?

Framework: Laravel 5

Upvotes: 0

Views: 47

Answers (1)

Andrius
Andrius

Reputation: 5939

You have an object, in an array, you can notice that since you have curly braces ({}) around your variables.

You will need to use $subpage[0]->name to access the value just like you would in a controller, to access some model's object.

Upvotes: 2

Related Questions