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

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.

Last updated 2 years ago.
0

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

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Luddinus luddinus Joined 18 Apr 2014

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.