Naming Conventions

File convention naming

  • we add a suffix of the abstracted object to the end on all abstraction EXCEPT Model Controller UserController, AmlController

  • Action updateUserAction, createUserAction

  • Repository userAmlRepository, userBankAccountRepository

  • Service Provider RepositoryServiceProvider, DomainServiceProvider

  • the same thing applied for Exception, Event, Listener, Service, and Interface.

General variables in PHP - please name them with full name for instance: $payload, $dealInvestmentId, $UserWalletTransactionCollection, foreach ($dealInvestments as $dealInvestment), do NOT use $i, $k, $l, $m, $x, $y, $z

What
How
Good
Bad

Model

Singular, Snake case, Separator under score

User_aml

UserAml, UsersAml, User-Aml, Users-Aml

Controller

Singular

ArticleController

ArticlesController

Route

Plural with dash separator

/user/get-bank-details

article/1, userGetBankDetails

Named route

Snake case with dot notation as per route, Separator is underscore

user.get_bank_details

users.get_bank_details

Model multiple words

singular

User_update

User_updates

hasOne or belongsTo relationship

singular

articleComment

articleComments, article_comment

All other relationships

hasOne - singular, hasMany - plural

articleComment, articleComments

article_comments

Table

Singular, snake_case

Article_comment

articleComments, article_comments

Pivot table

Singular model names in alphabetical order

article_order

User_article, articles_user

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

user_id

Migration

singular

2022_01_01_000000_creat e_article_table

2022_01_01_000000_articl es,

2020-11-16-alter-table-user- table

Method

camelCase

getAll()

get_all

Method in resource controller

Table name

store

saveArticle

Methos in test class

Snake_case without prefix

test

guest_cannot_see_article

testGuestCannotSeeArticle

Variable

camelCase

$articlesWithAuthor

$articles_with_author

Collection

Descriptive, plural

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

$active, $data

Object

Descriptive, singular

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

$users, $obj

Language files index

snake_case

Laravel-slack, crm-system

View

kebab-case

show-filtered.blade.php

showFiltered.blade.php, show_filtered.blade.php

Config

kebab-case

Laravel-slack, crm-system

laravelSlack, crmSystem

Interface

Adjective or noun

AuthenticationInterface

Authenticable, Authentication

Last updated