Database/model field-name convention in Laravel?

喜你入骨 提交于 2019-12-10 13:39:11

问题


I understand that camel case is the usual convention, as per http://forums.laravel.io/viewtopic.php?id=8857

However, Laravel is using created_at and updated_at for timestamp fields.

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?

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...


回答1:


Snake case is the convention for database fields and model attributes.

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.



来源:https://stackoverflow.com/questions/21400711/database-model-field-name-convention-in-laravel

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