Laravel中的数据库/模型字段名称约定? [英] Database/model field-name convention in Laravel?
问题描述
根据 http://forums.laravel.io/viewtopic,我了解骆驼式旅行箱是通常的惯例.php?id = 8857
但是,Laravel在时间戳字段中使用了created_at和Updated_at.
However, Laravel is using created_at and updated_at for timestamp fields.
我很困惑,数据库中字段名的最佳命名约定是什么?如果使用了驼峰式,那么我可以再将created_at切换到createdAt吗,还是应该将驼峰式大小写用于自己的字段,而将蛇形大写用于时间戳?
I'm confused as what would be the best naming convention for field-names in the database? If camel cased, can I then switch created_at to createdAt, or should I use camel case for own fields and snake case for the timestamps?
对我来说似乎不清楚.也许Laravel希望我一直使用大写字母,例如数据库中的first_name和PHP代码中的$ first_name,而不是数据库中的firstName和代码中的$ firstName?
It doesn't seem clear to me. Maybe Laravel wants me to use snake case all the way, like first_name in the database and $first_name in the PHP code, rather than firstName in the database, and $firstName in the code?
我希望有人可以澄清...
I hope someone can clarify...
推荐答案
蛇形格式是数据库字段和模型属性的约定.
Snake case is the convention for database fields and model attributes.
您可以在getter和setter中看到它( http://laravel.com/docs/eloquent#accessors-and-mutators )或关系部分( http://laravel.com /docs/eloquent#relationships ).
You can see it in the getter and setter (http://laravel.com/docs/eloquent#accessors-and-mutators) or relationships sections (http://laravel.com/docs/eloquent#relationships) in the documentation.
这篇关于Laravel中的数据库/模型字段名称约定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!