patrick
patrick

Reputation: 881

Laravel - JSON in view / Eloquent error

I am trying to return a specific value in my Laravel view. I define a variable in my controller and pass it on to my view. This is what I get when my blade code looks like this:

<h1>{{ $sport }}</h1>

enter image description here

However, since this is returned in my view and I only want to have the "sport" itself I did this:

<h1>{{ $sport->sport }}</h1>

Undefined property: Illuminate\Database\Eloquent\Collection::$sport

Any help would be much appreciated.

Thanks

Upvotes: 1

Views: 198

Answers (1)

Rezigned
Rezigned

Reputation: 4942

You are referencing an Array Collection not an object itself

Try

<h1>{{ $sport->first()->sport }}</h1>

Or modify your controller like this

// Controller
return View::make('sports', array('user' => $sport->first()));

// View
{{ $sport->sport }}

Upvotes: 3

Related Questions