@romain I missed there were a pivot table between ShowDetails and Actor models.
So in the database level you have four tables, right?
show --- show_details --{ actor_show_details }-- actors
The ->hasManyThrough is handy, but basically what it does is adding a join to one intermediary model's table.
But here we need more joins. One less talked about Eloquent feature is that you can customize the query builder been used as the relation source.
Try adding this relation to your Actor model:
class Actor extends Model
{
// ... other code
public function showDetails()
{
return $this->belongsToMany(ShowDetails::class);
}
public function shows()
{
$query = Show::query()
->selectRaw('shows.*, actor_show_details.actor_id')
->join('show_details', 'show_details.show_id', 'shows.id')
->join('actor_show_details', 'actor_show_details.show_details_id', 'show_details.id');
return $this->newHasMany($query, $this, 'actor_show_details.actor_id', 'id');
}
}
You might need to change some columns names if needed. I tried guessing based on the conventions from how you described your models/tables.
Then you'll just need to:
$shows = $actor->shows;
Hope it helps.