Mohsen Jalalian
Mohsen Jalalian

Reputation: 1130

Laravel controller name should be plural or singular?

What is the naming convention in Laravel for controllers? They should be singular or plural. I saw some people use singular and some people use plural for that. What is the correct form?

Upvotes: 40

Views: 26691

Answers (3)

Md. Amirozzaman
Md. Amirozzaman

Reputation: 1125

You should follow those naming convention:

  1. Model Name should be singular e.g: 'Profile', not 'Profiles'
  2. Controller name should be singular with 'Controller' suffix e.g: 'ProfileController', not 'ProfilesController'
  3. Php class Name should be in 'StudlyCase' format e.g: 'TestClass'
  4. Php function Name should be in 'camelCase' format e.g: 'testFunction'
  5. Class constants MUST be declared in all upper case with underscore separators; for example:

    class Foo
    {
        const VERSION = '1.0';
        const DATE_APPROVED = '2012-06-01';
    }
    

Useful link:

https://www.php-fig.org/psr/psr-1/

Upvotes: 16

learnjourney
learnjourney

Reputation: 653

Plural. Although the official laravel docs use singular for controller names, it is very well known that most of prominent laravel developers such as Jeffrey Way, Adam Wathan, Chris Fidao and many others uses plural for controller names that it sort of become the actual standard.

You are far better off using plural so you feel less confusion when you watch their videos, read their blog posts.etc

Upvotes: 1

Sohel0415
Sohel0415

Reputation: 9853

Here is a list of naming conventions accepted by Laravel community. According to this, Controller name should be Singular although you could chose your own convention as your need or how your team prefer.

Upvotes: 62

Related Questions