dimanche 29 janvier 2017

Checking value of a related model in Laravel

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.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire