• Published:August 21st, 2013
  • Category:Lavarel4, php

Laravel supports the PHP Framework Interop Group naming conventions. You can find them on the PHP-FIG website.

In short:

  • Generally database columns are snake_case but property names are camelCase. Eloquent is able to do the conversion automatically.
  • Class names must be declared in StudlyCaps.
  • Class constants must be declared in all upper case with underscore separators.
  • Method names must be declared in camelCase. (this used to be snake_case in L3)
  • Property names and function arguments have generally not a specific rule, but must be written according to the package. The Laravel doc about the convention doesn’t give more information about property names.. The only rule is: always use the same. I would suggest camelCase.
  • Function names are camelCase. (however the Official PHP coding standards advices snake_case).
  • For Variables names I would suggest camelCase, however snake_case is advised by the Official PHP coding standards, in contrast with the recommandations from the Zend Framework, which explicitly forbids underscores. Variables are not mentioned in the PHP Framework Interop Group and I can’t find any examples in the base Laravel framework because all variable names are single words.

I’d like to add that naming conventions are a controversial subject, because a lot of standard PHP functions don’t follow any naming convention.

Rss Comments


  1. Thank you for taking timeout to write this. I was looking exactly for this kind of naming convention list for L4! 🙂

    #1 Priyank Maniar
  2. Thanks for the information. It was useful. Is there any update for Laravel 5 or same rules apply?

    #2 Hardik Thakker
  3. […] « Laravel Naming Conventions ». developed.be. http://developed.be/2013/08/21/laravel-naming-conventions/ […]

    #3 Les fichiers de migration de Laravel : pour créer les tables de la BD
  4. Thank you for this.

    Hardik I am guessing they should be the same for Laravel 5 this is as of 5.4 im writing this comment.

    #4 Christopher

Leave a comment

Wordpress.org clearPaper by CreativeBits.it Copyright © 2012-2019 Robin Brackez. All rights reserved. By visiting this site you agree to accept cookies that are purely used to check how many visitors I have. Theme by: creativebits. Custom adaptations by Robin Brackez.