I have 3 tables:
: :
id | name
: :
id | address | venue_id | city_id
: :
id | name | slug | display_name
a venue hasOne location, a location belongsTo a venue.
a location belongsTo a city,a city hasMany locations.
now, what's the relation between a venue and a city ?
how can I get queries from venue based on filtering city I mean execute "where" on city slug.
How can I get all venues from a city model?
Use a HasManyThrough
relationship:
class City extends Eloquent
{
public function venues()
{
return $this->hasManyThrough(App\Venue::class, App\Location::class);
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.