长命名使用下划线还是驼峰?

长命名使用下划线还是驼峰?

《L01 基础入门》
我们将带你从零开发一个项目并部署到线上,本课程教授 Web 开发中专业、实用的技能,如 Git 工作流、Laravel Mix 前端工作流等。
《L04 微信小程序从零到发布》
从小程序个人账户申请开始,带你一步步进行开发一个微信小程序,直到提交微信控制台上线发布。
讨论数量: 10

类文件 => 大驼峰,普通文件=> 下划线,方法 => 小驼峰,函数 => 下划线,变量 => 小驼峰,常量 => 全大写 +下划线

2年前 评论
chowjiawei

看你公司的规范,如果都是用驼峰,就也还是驼峰,比如 aBadAppleBelongBoss 长点没事 只要清晰易懂是最主要的

2年前 评论

看这个项目的规范,如果是新项目建议驼峰,和laravel保持一致,如果是老项目,以前怎么命名现在就这么命名!

2年前 评论

python下划线,php和java驼峰

2年前 评论

保证项目整齐划一,PSR规范都可以。

2年前 评论

类文件 => 大驼峰,普通文件=> 下划线,方法 => 小驼峰,函数 => 下划线,变量 => 小驼峰,常量 => 全大写 +下划线

2年前 评论

路由中的url部分,用中划线。参数部分用下划线

2年前 评论
Complicated

和团队保持一致,没有的话就使用驼峰

2年前 评论

下划线太多,一行会太多字,建议驼峰

2年前 评论

变量用小写下划线,其余用驼峰

2年前 评论
pndx

Follow Laravel naming conventions

Follow PSR standards.

Also, follow naming conventions accepted by Laravel community:

What How Good Bad
Controller singular ArticleController ArticlesController
Route plural articles/1 article/1
Named route snake_case with dot notation users.show_active users.show-active, show-active-users
Model singular User Users
hasOne or belongsTo relationship singular articleComment articleComments, article_comment
All other relationships plural articleComments articleComment, article_comments
Table plural article_comments article_comment, articleComments
Pivot table singular model names in alphabetical order article_user user_article, articles_users
Table column snake_case without model name meta_title MetaTitle; article_meta_title
Model property snake_case $model->created_at $model->createdAt
Foreign key singular model name with _id suffix article_id ArticleId, id_article, articles_id
Primary key - id custom_id
Migration - 2017_01_01_000000_create_articles_table 2017_01_01_000000_articles
Method camelCase getAll get_all
Method in resource controller table store saveArticle
Method in test class camelCase testGuestCannotSeeArticle test_guest_cannot_see_article
Variable camelCase $articlesWithAuthor $articles_with_author
Collection descriptive, plural $activeUsers = User::active()->get() $active, $data
Object descriptive, singular $activeUser = User::active()->first() $users, $obj
Config and language files index snake_case articles_enabled ArticlesEnabled; articles-enabled
View kebab-case show-filtered.blade.php showFiltered.blade.php, show_filtered.blade.php
Config snake_case google_calendar.php googleCalendar.php, google-calendar.php
Contract (interface) adjective or noun AuthenticationInterface Authenticatable, IAuthentication
Trait adjective Notifiable NotificationTrait
2年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!