1

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

1
  • What happens if you put $sportvalue = $sport->sport; in your controller and then <h1>{{ $sportvalue }}</h1> in your view ? Commented Jan 31, 2014 at 2:08

1 Answer 1

3

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 }}
Sign up to request clarification or add additional context in comments.

2 Comments

Bingo. Can see this in the JSON - it starts with a [ - array - not { - object.
thanks a lot! Modifying the controller worked. I used get() and not first() before.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.