Model and table name conventions Laravel

那年仲夏 提交于 2019-12-12 17:07:34

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!