0

I am successfully getting results in/from my controller like this:

$session_id and $user_id are getting passed into my method.

Controller

// get all sets belonging to the user for the given session
$session = Session::findOrFail($session_id);
$sets = Set::where('session_id', $session_id)->where('user_id', $user_id);    
$user = User::findOrFail($user_id);

return View('users.index')
    ->with('session', $session)            
    ->with('sets', $sets)
    ->with('user', $user);

View

<p>{{ $user->first_name }} has {{ $sets->count() }} existing set{{ ($sets->count() > 1 ? 's': '') }}.</p>
<ul class="list-unstyled">
    @foreach ($sets as $set)
        <li>
            <a href="{{ ur('/sessions/'.$session->id.'/user/'.$user->id.'/long-snap/set/'.$set->id) }}">Set</a>
        </li>
    @endforeach
</ul>

I am seeing "Foo has 1 existing set." and I can see the record in the DB. However, I'm not getting into the loop at all. If I add/remove records, my paragraph text updates accordingly as well - but I still never get into the loop to show each set. I'm sure it's something obvious, but I sure don't see it.

Thank you for any suggestions!

3
  • Just dd($user) before returning the view and show me the output. Also you have not written whole query of sets you have to get() or first() method to get collection or array @Damon Commented Nov 19, 2016 at 5:18
  • Doing dd() was giving me back the object, but as you pointed out it was the get() I was missing. Thank you! Commented Nov 19, 2016 at 13:48
  • It was pleasure to help you 😊! Commented Nov 19, 2016 at 16:35

1 Answer 1

1

Change the query of sets to this:

$sets = Set::where('session_id', $session_id)->where('user_id', $user_id)->get();

As get() method will return you the collection object.

Sign up to request clarification or add additional context in comments.

2 Comments

SEE I KNEW IT WAS SOMETHING OBVIOUS! :) Thank you.
Welcome @Damon!

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.