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:
Class names: Class names should be declared in
StudlyCaps (also known as CamelCase) style
, with thefirst letter of each word capitalized, without underscores
, and with no prefixes. For example:MyClassName
.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
.Constant names: Constant names should be declared in all
uppercase letters with underscores
separating words. For example:MY_CONSTANT
.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
.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.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
.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
.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
.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)
Hi! Thank you for this note, good to have it all in one place.
Could you clarify the source of this statement?
In Laravel docs it says that the resource controller name will be in the singular form.