Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?

like image 596
Mohsen Jalalian Avatar asked Dec 30 '17 05:12

Mohsen Jalalian


People also ask

Should controller name singular or plural?

A controller is plural because it is the controls (methods) for the collection of Users.

How do I name a controller in laravel?

Naming Controllers Controllers should be in singular case, no spacing between words, and end with "Controller". Also, each word should be capitalised (i.e. BlogController, not blogcontroller). For example: BlogController , AuthController , UserController .

Should folder names be plural?

The pluralization of a directory's name depends on the relationship between the name and the contents of the directory. A directory's name should be plural when it describes the type of files the directory contains.

What is the controller in laravel?

Controllers can group related request handling logic into a single class. For example, a UserController class might handle all incoming requests related to users, including showing, creating, updating, and deleting users. By default, controllers are stored in the app/Http/Controllers directory.


Video Answer


3 Answers

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.

like image 134
Sohel0415 Avatar answered Oct 17 '22 04:10

Sohel0415


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/

like image 40
Md. Amirozzaman Avatar answered Oct 17 '22 03:10

Md. Amirozzaman


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

like image 1
learnjourney Avatar answered Oct 17 '22 04:10

learnjourney