Closed TheFrankman closed 4 years ago
Don't worry, i got there. The solution is :
public function organisation(): HasOneDeep
{
return $this->hasOneDeep(
Organisation::class,
['customer_user', Customer::class],
[null, null, 'id'],
[null, null, 'organisation_id'],
)->latest('organisations.created_at');
}
Hello there.
Not an Issue, just can't find the correct combination of relationships.
In my system an
organisation
hasManycustomers
, acustomer
hasManyusers
. I can get theusers
for anorganisation
using the following :The inverse of this relationship is proving difficult. I'm trying to get the
organisation
for auser
.user
hasManycustomers
customer
belongsToorganisation
BUT all of a users customers belong to the sameorganisation
so it will need some kind of ->first() on there as well i imagine...I could obviously just have the organisation_id stored against the user, but If I can get the relationship working it's an arbitrary field as it would never change.
Table structure