模型和表命名约定 Laravel
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/47936761/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Model and table name conventions Laravel
提问by Harman
I want to know model and table conventions in Laravel.
我想知道 Laravel 中的模型和表格约定。
I have table users and user_address now I do not want to use
我现在有表 users 和 user_address 我不想使用
protected $table = "user_address"
受保护的 $table = "user_address"
property. Please suggest me the right convention in model or table.
财产。请建议我在模型或表格中使用正确的约定。
回答by Alexey Mezenin
回答by Sapnesh Naik
If your model name is User.php then Laravel expects class 'User' to be inside that file. It also expects userstable for User model (plural form).
如果您的模型名称是 User.php,那么 Laravel 期望类 'User' 位于该文件中。它还需要用户模型的用户表(复数形式)。
Similiarly, If you have a user_address
model your table should be user_addresses
同样,如果你有一个user_address
模型,你的表应该是user_addresses