Hello everyone
hopefully, I can describe this in a way that makes sense - I am having issues researching this as I worry I am missing some kind of understanding of database tables and I was looking to see if someone could point me in the right direction.
I am looking to get the parent of a parent on a model so an example of this would be 3 models that all have belongTo to eachother.
Customer > Site > Task
On the Task.php model I can use:
public function site()
{
return $this->belongsTo('App\Site');
}
To run $task->site and it will return site.
What I am trying to do is get what customer a task belongs to through the site e.g:
public function customer()
{
return $this->site->customer;
}
This works as a function but it is not a relationship.
I have looked into using defining custom intermediate tables (pivot tables) and also looked at doing joins and through relationships but I worry I might be looking at this issue in the wrong way.
I need this relationship exposed to display in a Nova table to I would much rather use a true relationship rather than a function - it is something I seem to hit in most projects so wanted to get my understanding checked!
How would others approach this?
Thanks for your help