In order to leverage on the Laravel Framework, its essential to apply the naming conventions.
Here are the basics on my recommended naming convention based on current Laravel practices and recommendations at PSR 4 and other PSR
Database
Tables names
- Lower case with underscore to separate words
- In Plural form
- No spaces
Example:
orders, customers, customer_locations
Column names
- Lower case with underscore to separate words
- Singular form
- Shouldn't reference table name. For example, column name id is unique and used to keep track of specific row.
Pivot tables
- Lower case with underscore to separate words
- In singular form
Example:
customer_order
Foreign keys
- Lower case with referenced model name and append with '_id'
- In singular form
Example:
customer_id, order_id
Variables
- start with lower case is camelCase.
- In singular form
- When variables contain array or collection of items, then name is in plural form
Example:
$customers = Customer::all( );
$customer = Customer::first( );
Controllers
- Begin with Upper case, is camelCase and appends with "Controller"
- In Singular form
Example:
CustomerController
Models
Model names
- Begin with upper case, is camelCase to separate words.
- In Singular form
- Avoid short form of words
Example:
Customer, User
Model properties
- Lower case with underscore to separate words
- Is singular, and follow the related table column name
Example:
$updated_at, $description
Model methods
- Begin with lower case and is camelCase
- Singular or Plural depends on the return value.
- Avoid repeating the class name where possible.
Example:
index( ), reset( ), getOrder( ), getOrders( )
Routes
- All in lowercase and use the hypen to separate words.
- Use curly braces to store object(s)
- Use correct HTTP methods (GET, POST, PUT, DELETE) to determine which controller method is called
- Use standard route name (index, create, store, show, edit, update, destroy)
Blade view
View Folders
- Begin with lower case and is camelCase
- In Singular form
- No spaces
Example:
customer, order
View Files
- Lower case with underscore to separate words
- Descriptive and avoid abbreviations or short names
- No spaces
Example:
show.blade.php, index.blade.php
No comments:
Post a Comment