Answer the question
In order to leave comments, you need to log in
How to correctly formulate the sampling conditions for the linking model?
Good evening everyone. I am using Laravel 5.2. It is necessary to display events from a specific city.
There are 3 models: Event, Place, City
with the following relationships:
Relationships in models:
Event
public function place()
{
return $this->belongsTo('App\Models\Place');
}
public function city()
{
return $this->belongsTo('App\Models\City');
}
public function getExpectedEvents()
{
$events = Event::expected()->with([
'cover' => function ($query) {
$query->where('is_cover', 1);
},
'place.city' => function ($query) {
// например так
$query->where('slug', 'название города');
}
])->get();
}
->with(['cover' => function ($query) {
$query->where('is_cover', 1);
},
Answer the question
In order to leave comments, you need to log in
You have some kind of iodine-style. There is a city slug, so we dance from this side
City::where('slug', 'city name')->with('place.events')->get();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question