What is the difference between using belongsToMany() or hasManyThrough() when defining a Many To Many relationship in Laravel?
Example:
User
Account
Account_User
So, User has a many to many relation to Account via the Account_User table. On top of being just the pivot table that defines the related Users with related Accounts, it also stores a Account_User.role
field, which determines which role a given user has in a given account.
What would the implications be of using either User belongsToMany() Account
or User hasManyThrough() Account Account_User
? Or is this essentially the same?
When decided upon a method, I guess I should use the same method for the reverse relation definition.