I have users. Users have a relationship with a country, and country has a region.
I would like to access all users who are within a region, and I am doing it through their related country, like this:
user->country->region
When I tried to use whereHas, like this:
$users = User::whereHas('country', function ($query) {
$query->where('region', 3);
})
->get();
I got an error that said there was an unexpected } on the 3rd line. I would like to know what is the best method of doing this.
Use Laravel Eloquent relationship, In Laravel eloqunent there are Has Many Through option available for as per your requirement. Please check this :-> Here is laravel documentation link