laravel/eloquent дублирование запросов с with
Есть CarRoute, который имеет множество CarRouteSection(отрезок). Отрезок имеет две точки start_point и end_point. Как в таком случае избавиться от дублирования?
public function start_point(): HasOne
{
return $this->hasOne(CarPoint::class, 'id', 'start_point_id');
}
public function end_point(): HasOne
{
return $this->hasOne(CarPoint::class, 'id', 'end_point_id');
}
$routes = CarRoute::with(['sections.start_point', 'sections.end_point'])->get();
@foreach ($routes as $route)
@foreach($route->sections as $section)
{{ $section->id }}
{{ $section->start_point->latitude }}
{{ $section->start_point->longitude }}
{{ $section->end_point->latitude }}
{{ $section->end_point->longitude }}
{{ $section->moving_time }}
@endforeach
@endforeach
