I have a pivot table by the name of account_user_permissions that joins the accounts, users, and permissions tables together. I have already set up a custom pivot model class by the name of AccountUserPermission that defines a belongsTo relationship to my account, user, and permission models.
On my account, user, and permission models, I define the newPivot function, and check the type of the model passed in:
// This method is on my user model
public function newPivot(Model $parent, array $attributes, $table, $exists, $using = null)
{
if ($parent instanceof Account) {
return new AccountUserPermission($parent, $attributes, $table, $exists, $using);
}
return parent::newPivot($parent, $attributes, $table, $exists, $using);
}
I am trying to add to this pivot table when I create a new account, user, and permission, but I can't figure out how to add to it because there are three relationships on the pivot. Normally, you can just attach straight to a pivot table.
Am I implementing this correctly? I can't seem to get an answer out of anybody on this forum, I'm continuously ignored when it comes to pivot tables between multiple tables. Can someone please just tell me if I'm doing it wrong?