Good morning,
I would like to retrieve data from an intermediary table on an belongsTo relationship.
Here is an extract from my database schema.
An organization has many members via the table organization_user
Users has many Organization via the table organization_user
A user has only one position in an organisation. So only one row in the organization_user table per user/organization pair
A contract has a representative via its representative_id field.
Currently I get the User object via an belongsTo relationship like this:
public function representative()
{
return $this->belongsTo(User::class);
}
however I want to retrieve the contract representative through the organization_user table to retrieve the value of the "position" field. How do I do this?
2 - Have a relation between organization and contract (this is more tricky). Add a foreign key to contracts table referencing organizations and use something like this