如影随形

影子是一个会撒谎的精灵,它在虚空中流浪和等待被发现之间;在存在与不存在之间....

您现在的位置是:首页>laravel

laravel社区认可的命名规范

发布时间:2019-11-25编辑: 浏览(2158)


    对象

    规则

    更优的写法

    应避免的写法

    控制器

    单数

    ArticleController

    ArticlesController

    路由

    复数

    articles/1

    article/1

    路由命名

    带点符号的蛇形命名

    users.show_active

    users.show-active, show-active-users

    模型

    单数

    User

    Users

    hasOne或belongsTo关系

    单数

    articleComment

    articleComments, article_comment

    所有其他关系

    复数

    articleComments

    articleComment, article_comments

    表单

    复数

    article_comments

    article_comment, articleComments

    透视表

    按字母顺序排列模型

    article_user

    user_article, articles_users

    数据表字段

    使用蛇形并且不要带表名

    meta_title

    MetaTitle; article_meta_title

    模型参数

    蛇形命名

    $model->created_at

    $model->createdAt

    外键

    带有_id后缀的单数模型名称

    article_id

    ArticleId, id_article, articles_id

    主键

    -

    id

    custom_id

    迁移

    -

    2017_01_01_000000_create_articles_table

    2017_01_01_000000_articles

    方法

    驼峰命名

    getAll

    get_all

    资源控制器

    table

    store

    saveArticle

    测试类

    驼峰命名

    testGuestCannotSeeArticle

    test_guest_cannot_see_article

    变量

    驼峰命名

    $articlesWithAuthor

    $articles_with_author

    集合

    描述性的, 复数的

    $activeUsers = User::active()->get()

    $active, $data

    对象

    描述性的, 单数的

    $activeUser = User::active()->first()

    $users, $obj

    配置和语言文件索引

    蛇形命名

    articles_enabled

    ArticlesEnabled; articles-enabled

    视图

    短横线命名

    show-filtered.blade.php

    showFiltered.blade.php, show_filtered.blade.php

    配置

    蛇形命名

    google_calendar.php

    googleCalendar.php, google-calendar.php

    内容 (interface)

    形容词或名词

    Authenticatable

    AuthenticationInterface, IAuthentication

    Trait

    使用形容词

    Notifiable

    NotificationTrait


关键字词:laravel