3

I have 3 tables.

The first two tables are Groups and Accounts.

  • An account can belong to many groups.

  • A group can have many accounts.

  • In other words it is a many to many relationship.

Therefore I need a 3rd table, which is a join table

What is the recommended naming convention of this join table in Laravel (or perhaps in general).

Is there any naming conventions?

I was planning to call it "GroupsAccountAssignment".

Yahya Uddin
  • 26,997
  • 35
  • 140
  • 231

1 Answers1

5

The name of the pivot table should be account_group.

As given in laravel docs

To define this relationship, three database tables are needed: users, roles, and role_user. The role_user table is derived from the alphabetical order of the related model names, and contains the user_id and role_id columns.

Though, you can always overwrite the default naming convention like below:
Account Model:

return $this->belongsToMany('App\Group', 'GroupsAccountAssignment', 'account_id', 'group_id');
jaysingkar
  • 4,315
  • 1
  • 18
  • 26