🎄P
Size: a a a
🎄P
🎃
$countryId = 1;
Trip::where(function($query) use($countryId): void {
$query->where('status', 'new')->whereHas('destinations', function($query) use($countryId): void {
$query->where('country_id', $countryId);
});
})->orWhere(function($query) use($countryId): void {
$query->where('status', 'has_report')->whereHas('report.destinations', function($query) use($countryId): void {
$query->where('country_id', $countryId);
});
});
S
🎄P
🎄P
🎄P
🎄P
v
$countryId = 1;
Trip::where(function($query) use($countryId): void {
$query->where('status', 'new')->whereHas('destinations', function($query) use($countryId): void {
$query->where('country_id', $countryId);
});
})->orWhere(function($query) use($countryId): void {
$query->where('status', 'has_report')->whereHas('report.destinations', function($query) use($countryId): void {
$query->where('country_id', $countryId);
});
});
$countryId = 1;
$closure = function (string $status, string $relation, int $countryId): {
return function ($query) use($status, $relation, $countryId) {
$query->where('status', $status)->whereHas($relation, function($query) use($countryId) {
$query->where('country_id', $countryId);
});
};
};
Trip::where($closure('new', 'destinations', $countryId))->orWhere($closure('has_report', 'report.destinations', $countryId)
🎃
🎃
ЕП
public function destinationsBlabla()
{
if($this->status === 'new') {
return $this->hasMany(Destination::class', ...');
}
if($this->status === 'has_report') {
return $this->hasManyThrough(Destination::class', Repost::class, ...);
}
}
🎃
🎃
🎃
public function destinationsBlabla()
{
if($this->status === 'new') {
return $this->hasMany(Destination::class', ...');
}
if($this->status === 'has_report') {
return $this->hasManyThrough(Destination::class', Repost::class, ...);
}
}
🎃
v
🎃
ЕП