## 命名約定
遵循?[PSR 標準](http://www.php-fig.org/psr/psr-2/)。 另外,請遵循 Laravel 社區接受的命名約定:
| 類型 | 規則 | 正確示例 | 錯誤示例 |
| -------------------------------- | ------------------------------------------------------------ | --------------------------------------- | --------------------------------------------------- |
| 控制器 | 單數 | ArticleController | ~~ArticlesController~~ |
| 路由 | 復數 | articles/1 | ~~article/1~~ |
| 命名路由 | 帶點符號的蛇形命名 | users.show_active | ~~users.show-active, show-active-users~~ |
| 模型 | 單數 | User | ~~Users~~ |
| hasOne 和 belongsTo 模型關聯方法 | 單數 | comment | ~~comments, article_comment~~ |
| | | | |
| 其他模型關聯方法 | 復數 | comments | ~~articleComment, article_comments~~ |
| 數據表 | 復數 | article_comments | ~~article_comment, articleComments~~ |
| 多對多關聯的中間表(Pivot table) | 按字母順序排列的單數模型名稱 | article_user | ~~user_article, articles_users~~ |
| 數據表字段 | 小寫字母、單數、蛇形命名 | meta_title | ~~MetaTitle; meta_titles~~ |
| 外鍵 | 帶_id后綴的單數型名稱 | article_id | ~~ArticleId, id_article, articles_id~~ |
| 主鍵 | - | id | ~~custom_id~~ |
| Migration | - | 2017_01_create_articles_table, 2017_01_add_name_filed_on_articles_table | ~~2017_01_01_000000_articles~~ |
| Method Name | 小駝峰命名 | getAll | ~~get_all~~ |
| 資源控制器中的方法 | [具體看表格](https://laravel.com/docs/master/controllers#resource-controllers) | store、index、detail… | ~~saveArticle~~ |
| 單元測試類中的方法 | 小駝峰命名 | testGuestCannotSeeArticle | ~~test_guest_cannot_see_article~~ |
| 變量 | 小駝峰命名 | $articlesWithAuthor | ~~$articles_with_author~~ |
| 集合(Collection)類型數據的變量名 | 具描述性的復數形式 | $activeUsers = User::active()->get() | ~~$active, $data~~ |
| 對象 | 具描述性的單數形式 | $activeUser = User::active()->first() | ~~$users, $obj~~ |
| Config and language files index | 蛇形命名 | articles_enabled | ~~ArticlesEnabled; articles-enabled~~ |
| View文件 | 蛇形命名 | show_filtered.blade.php | ~~showFiltered.blade.php, show-filtered.blade.php~~ |
| Config文件 | 蛇形命名 | google_calendar.php | ~~googleCalendar.php, google-calendar.php~~ |
| 契約 (interface) | 形容詞或名詞 | Authenticatable | ~~AuthenticationInterface, IAuthentication~~ |
| Trait | 形容詞 | Notifiable | ~~NotificationTrait~~ |