laravel 5.5 控制器名称应该是复数还是单数?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/48031176/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 17:10:45  来源:igfitidea点击:

laravel 5.5 controller name should be plural or singular ?

phplaravellaravel-5naming-conventions

提问by Mohsen Jalalian

what is the naming convention in laravel 5.5 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 ?

Laravel 5.5 中控制器的命名约定是什么?它们应该是单数或复数。我看到有些人使用单数,有些人为此使用复数。什么是正确的形式?

回答by Sohel0415

Hereis a list of naming conventionsaccepted by Laravel community. According to this, Controllername should be Singularalthough you could chose your own convention as your need or how your team prefer.

Laravel 社区接受的命名约定列表。据此,控制器名称应为Singular,尽管您可以根据需要或团队的喜好选择自己的约定。

回答by Md. Amirozzaman

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';
    }
    
  1. 模型名称应该是单数,例如:“配置文件”,而不是“配置文件”
  2. 控制器名称应该是带有“Controller”后缀的单数,例如:“ ProfileController”,而不是“ProfilesController”
  3. Php 类名称应采用“StudlyCase”格式,例如:“ TestClass
  4. Php 函数名称应采用“camelCase”格式,例如:“ testFunction
  5. 类常量必须全部使用下划线分隔符以大写形式声明;例如:

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

Useful link:

有用的链接:

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

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

回答by learnjourney

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.

复数。虽然官方 Laravel 文档使用单数作为控制器名称,但众所周知,大多数著名的 Laravel 开发人员,例如 Jeffrey Way、Adam Wathan、Chris Fidao 和许多其他人使用复数作为控制器名称,这在某种程度上成为了实际标准。

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

您最好使用复数形式,这样您在观看他们的视频、阅读他们的博客文章等时就不会感到困惑