Laravel Naming Conventions - developed.be

  • Published:August 21st, 2013
  • Category:Lavarel, php
  • 2 comments

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

2 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

Leave a comment