Laravel Architecture

Follow Laravel Standard Naming Conventions for Predictable Architecture

Punyapal Shah 3 min read
edit this tip
A complete reference guide to Laravel community naming conventions across models, controllers, migrations, relationships, routes, views, enums, and tests.

Following standard naming conventions allows Laravel's internal reflection engines (including route model binding, Eloquent relation resolution, and migration schema builders) to function automatically without manual configuration.

Complete Naming Conventions Cheat Sheet

ComponentConventionGood ExampleBad Example
ControllerSingular (PascalCase)ArticleControllerArticlesController
ModelSingular (PascalCase)User, OrderUsers, Orders
Migration TablePlural (snake_case)articles, order_itemsarticle, orderItems
Pivot TableSingular alphabetical (snake_case)article_user, order_productarticles_users, user_article
Table Columnsnake_case without model prefixmeta_title, statusMetaTitle, article_meta_title
Model Propertysnake_case$user->created_at$user->createdAt
Primary KeyDefault ididarticle_id, custom_id
Foreign KeySingular model + _iduser_id, order_iduser_fk, id_user, users_id
Relationship (hasOne / belongsTo)Singular (camelCase)user(), articleComment()users(), article_comment()
Relationship (hasMany / belongsToMany)Plural (camelCase)comments(), roles()comment(), article_comments()
Route URIPlural (kebab-case)/articles/{article}/article/{id}, /view_articles
Route NamePlural resource dot notationarticles.index, orders.showshow_article, articleShow
View Templatekebab-caseshow-filtered.blade.phpshowFiltered.blade.php, show_filtered.blade.php
Config Filesnake_caseconfig/google_calendar.phpgoogleCalendar.php, google-calendar.php
Config Keysnake_caseconfig('services.stripe_key')config('services.StripeKey')
Contract (Interface)Adjective or Noun (PascalCase)Authenticatable, PaymentGatewayIAuthentication, AuthInterface
TraitAdjective (PascalCase)Notifiable, SluggableNotificationTrait, TraitNotifiable
EnumSingular (PascalCase)UserRole, OrderStatusUserRoles, UserRoleEnum
Form RequestSingular Action + Model + RequestUpdateUserRequest, StorePostRequestUserFormRequest, UserRequest
SeederSingular (PascalCase)UserSeeder, OrderSeederUsersSeeder, OrdersSeeder
Resource Controller ActionStandard REST verbindex, store, updategetAll, saveArticle
Class MethodcamelCasegetFullName(), processPayment()get_full_name(), ProcessPayment()
Test MethodcamelCase or test_ snake_casetestUserCanPurchase(), it_charges_order()UserCanPurchase
Collection VariableDescriptive plural$activeUsers = User::active()->get()$data, $active, $usersList
Single Model VariableDescriptive singular$user = User::first()$users, $obj, $item

Why Conventions Matter

  1. Automatic Relation Resolution: Eloquent infers foreign keys and pivot tables automatically without requiring manual string parameters.
  2. Implicit Route Model Binding: Type-hinting Article $article on /articles/{article} resolves the model with zero controller boilerplate.
  3. Consistency: Engineers moving between Laravel projects immediately know where files live and how methods are named.

Summary

  • Eliminates redundant $table, $primaryKey, and relationship foreign key parameters.
  • Guarantees predictable codebase navigation across development teams.
  • Follows standard PHP-FIG PSR-12 and Laravel framework conventions.
Tags: Laravel Architecture Best Practices Clean Code
Share on X

// Found an issue or want to contribute a tip? github.com/MrPunyapal/tips