Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 2 years ago.
0

Look into whereHas for filtering the result based upon existence of relationship.

0

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?

0
$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.

0

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();
Last updated 9 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

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.