It seems like a good use case for hasManyThrough: https://laravel.com/docs/8.x/eloquent-relationships#has-many-through
Sep 13, 2020
5
Level 30
Can I have a field with a relation through another relation?
Hey there,
quite simple I think, is there a simple way to have access to a relationship through another one?
I have Show <-> Season <-> Episode
on each episode I want to show the Season and the Show name. For now I figured how to display it by doing:
public function fields(Request $request)
{
return [
ID::make(__('ID'), 'id')->sortable(),
BelongsTo::make('Season'),
Text::make('Show', function ()
{
return $this->season->show->name;
}),
];
}
It works fine, but I don't get a link to the show, I would have to write it myself.
Is there a way to have a link between episode and show without adding show_id on each episode?
thanks
Level 30
Please or to participate in this conversation.