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 ?
A controller is plural because it is the controls (methods) for the collection of Users.
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 .
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.
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.
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.
You should follow those naming convention:
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/
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With