That's not a use-case for hasManyThrough. Leave that relationship and just do a nested eager load:
$routes = DriverRoute::with('details.callout')->get();
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I'm trying to use the hasManyThrough relationship but it doesn't fetch the related model.
3 tables:
driver_routes
id
--- other fields
driver_route_details
id
route_id (FK to driver_routes.id)
callout_id (FK to callouts.id)
--- other fields
callouts
id
---other fields
The relationships on my models that are related:
DriverRoute.php:
public function details()
{
return $this->hasMany(DriverRouteDetail::class, 'route_id', 'id');
}
public function callouts()
{
return $this->hasManyThrough(Callout::class, DriverRouteDetail::class, 'callout_id', 'id', 'id');
}
DriverRouteDetail.php
public function callout()
{
return $this->belongsTo(Callout::class, 'callout_id', 'id');
}
public function route()
{
return $this->belongsTo(DriverRoute::class, 'route_id', 'id');
}
Callout.php
public function details()
{
return $this->hasMany(DriverRouteDetail::class, 'callout_id', 'id');
}
Looking at the Docs this seems correct, but when I request my driver routes, no callouts are related when in fact it should return at least one.
$routes = DriverRoute::with('callouts', 'details')->get();
This returns my DriverRouteDetail models correctly, but the callouts relation is empty.
What am I doing wrong here?
Please or to participate in this conversation.