Usually, when creating Models and Migrations, you should stick to Laravel's naming convention and use English words. Then, Laravel will try to guess names. In this lesson, I will advise you on choosing/customizing names in Laravel DB.
Break Default Table Names Convention? Careful.
For example, if you call your Model Role
, Laravel will know its table should be roles
. But what if names are different?
You can set the table names on the Model in the protected $table
property. So, if you have a singular role
for the table name, you would set it in the Role Model.
class Role extends Model{ protected $table = 'role'; // ...}
When using a belongs-to-many relationship, a pivot table should be created with the two tables' singular names in alphabetical order. For the users
and roles
relationship, it would be role_user
and would contain foreign keys to both tables.
Usually, foreign key fields are named with the...