samedi 29 juin 2019

Eloquent where clause based on other tables

One of my Laravel models is called Property, which contains all the Real Estate properties within my application. Each Property contains a city and country.

Therefor I have the following relational tables:

City_property (holds city of properties)

| id | city_id | property_id |
|----|---------|-------------|
| x  | 2       | 1           |

City_country (holds country of city)

| id | country_id | city_id |
|----|------------|---------|
| x  | 3          | 2       |

So when fetching all my Properties, I want to where clause on the Country of the properties, so I'm able to only fetch Properties where country = 5 (for example).



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire