Look into whereHas for filtering the result based upon existence of relationship.
not sure where to start on that. read somewhere that whereHas doesn't play nice with nested relations (user.group).
would you have an example that would pertain to my data structure?
$c = Company::whereHas('user', function($q)
{
$q->whereHas('group', function($q)
{
$q->where('name_short', '=', 'user');
});
});
#print_r($c->toJSON());
print_r($c);
Just tried that and my browser crashed, assuming that is not the solution. I feel I am close though.
Figured it out :)
$c = Company::where('active','=',1)->whereHas('user', function($q)
{
$q->whereHas('group', function($q)
{
$q->whereIn('group.name_short', array('admin','user'));
});
})->get();
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community