Monday, March 6, 2017

LARAVEL: One-to-one relationship on a pivot table?

I can't think of how to handle this in Eloquent. I have a many-to-many relationship that needs a one-to-one relationship assigned to it.

Here is the basic database structure I designed in its simplest form:

ACCOUNTS: id

AGENTS: id

FEES: id

ACCOUNT_AGENT: account_id, agent_id, fee_id

Each Account belongsToMany Agents.

Each Agent belongsToMany Accounts.

Each "Account_Agent" (the many-to-many pivot table) belongsTo Fee.

How do I define that third relationship in an Eloquent model?

Thanks, hopefully my question is clear.



via Stephen Fox

Advertisement