Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Database/model field-name convention in Laravel?

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

like image 888
preyz Avatar asked Jan 28 '14 08:01

preyz


1 Answers

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.

like image 183
Alexandre Butynski Avatar answered Sep 29 '22 01:09

Alexandre Butynski