wiki

View on GitHub

Laravel naming conventions

Laravel tuân thủ theo chuẩn PSR-2(coding standard) và PSR-4(autoloading standard).

Dưới đây là 1 số convention cần lưu ý:

1. Route

a, Route name

Route('/users/download-file', [
    'as' => 'users.download_file',
    'uses' => 'UserController@downloadFile'
]);

b, Group route

c, Url

Route::get('/users/1/download-document', ['uses' => 'UserController@downloadDocument'])->name('users.download_document');

d, Method

2. Controller

a, Controller name

b, Method

3. Model

a, Name

b, Property

c, Method

Xem thêm tại Defining Relationships

4. Database

a, Tên table

b, Tên column

c, Khóa chính

d, Khóa ngoài

5. Tên thư mục , tên file

a, Thư mục

b, View

c, Config file, Language

6. Tên biến