Support the ongoing development of Laravel.io →
posted 8 years ago
Eloquent
Last updated 1 year ago.
0

In this line

$the_group = Group::with('users')->Name($query) -> get();

change get() to first() like this:

$the_group = Group::with('users')->Name($query) -> first();

Get returns a collection of Models (even if there are only 0 or 1 results) and the collection doesn't have a relationship, the model has.

So either just retrieve 1 model from the database with first() or loop through your collection to access the single model instances.

0

Perfect. That makes sense. I really appreciate your reply - thanks!

0

Sign in to participate in this thread!

Eventy

Your banner here too?

edfearon edfearon Joined 28 Aug 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.