You need where in
and having count(distinct .. )
mix in SQL (MySQL). You can also do it with has
in some cases. Show the relation and the tables.
Well, this is the solution (thx to jarektkaczyk)
$countries = [1,5,9];
User::whereHas('countries', function ($q) use ($countries) {
$q->whereIn('users_countries.country_id', $countries);
}, '=', count($countries) )->get();
I asked the same in stackoverflow if anyone is interested: http://stackoverflow.com/questions/24961783/laravel-get-an-user-who-has-specific-relationships
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community