DEV Community

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

Posted on

1

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.

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (1)

Collapse
 
xedelweiss profile image
Mykhailo

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.

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay