问题
I want to know model and table conventions in Laravel.
I have table users and user_address now I do not want to use
protected $table = "user_address"
property. Please suggest me the right convention in model or table.
回答1:
If the name of the model is UserAddress
, the name of the table should be plural. So it will be user_addresses
.
Read more about Laravel naming conventions here.
回答2:
If your model name is User.php then Laravel expects class 'User' to be inside that file. It also expects users table for User model (plural form).
Similiarly, If you have a user_address
model your table should be user_addresses
来源:https://stackoverflow.com/questions/47936761/model-and-table-name-conventions-laravel