DEV Community

Cover image for Laravel Naming Conventions
Code Of Accuracy
Code Of Accuracy

Posted on

Laravel Naming Conventions

Laravel, a popular PHP framework, follows PSR-2 for its naming conventions, along with some additional conventions specific to the framework. Here are some of the conventions:

  1. Class names: Class names should be declared in StudlyCaps (also known as CamelCase) style, with the first letter of each word capitalized, without underscores, and with no prefixes. For example: MyClassName.

  2. Method names: Method names should be declared in camelCase style, with the first letter of the first word in lowercase and the first letter of each subsequent word capitalized, without underscores. For example: myMethodName.

  3. Constant names: Constant names should be declared in all uppercase letters with underscores separating words. For example: MY_CONSTANT.

  4. Variable names: Variable names should be declared in camelCase style, with the first letter of the first word in lowercase and the first letter of each subsequent word capitalized, without underscores. For example: myVariableName.

  5. Function names: Function names should be declared in snake_case style, with all letters in lowercase and underscores separating words. For example: my_function_name.

  6. Route names: Route names should be declared in snake_case style, with all letters in lowercase and underscores separating words. For example: my_route_name.

  7. View names: View names should be declared in snake_case style, with all letters in lowercase and underscores separating words. For example: my_view_name.blade.php.

  8. Controller names: Controller names should be declared in plural form, with the first letter of each word capitalized, without underscores, and with the word "Controller" added to the end. For example: MyControllerName.

  9. Model names: Model names should be declared in singular form, with the first letter of each word capitalized, without underscores. For example: MyModelName.

Following these conventions can help make your code more consistent and easier to read, which can ultimately make your development process more efficient.

Top comments (1)

Collapse
 
xedelweiss profile image
Michael

Hi! Thank you for this note, good to have it all in one place.

Could you clarify the source of this statement?

Controller names should be declared in plural form

In Laravel docs it says that the resource controller name will be in the singular form.