Laravel Naming Conventions

Routes

  • Routes consisting of a single word should be plural.
Route::get('/posts')
Route::get('/post')
  • Routes consisting of multiple words should be in ‘kebab-case’ and only the last word should be plural.
Route::get('/blog-posts')
Route::get('/blogPost')
  • Named Routes should be plural and ‘dot’ separated including the resource method.
->name('posts.index')
->name('post.list')

Controllers

  • Controllers should be ‘singular’ and in ‘PascalCase’, suffixed by the word ‘Controller’.
PostController, BlogPostController
PostsController, blogPostsController

Models

  • Models should be ‘singular’ and in ‘PascalCase’.
Post, PostComment
Posts, PostComments

Methods (Functions) and Properties (Variables)

  • Methods and Properties should be in ‘camelCase’.
setPostName()
set_post_name()

Pivot Models

  • Pivot models should be ‘singular’ and in ‘PascalCase’ and in ‘alphabetical’ order.
PostTag
postsTags

Pivot Tables

  • Pivot tables should be ‘singular’ and in ‘snake_case’ and in ‘alphabetical’ order.
post_tag
PostsTags, postTags

Table Names

  • Table names should be in ‘snake_case’ and the last word should be plural.
posts, post_comments
post,PostComments, postComment

File Names (Including blade views)

  • File names should be in ‘snake_case’ and this includes the ‘blade’ view files.
active_users.blade.php
activeUsers.blade.php, active-users.blade.php

Configuration

  • Configuration files should be in ‘snake_case’.
utility_helper.php
utilityHelper.php, utility-helper.php

Policies

  • Policies should be ‘singular’ and in ‘PascalCase’ (same as the Models) and suffixed with the word ‘Policy’.
PostPolicy.php
postPolicies.php, Post-policy.php

--

--

--

Welcome! I am a senior Laravel developer and here will you find all sorts of information and tutorials around Laravel, PHP, and other web development languages.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Laravel 6 JWT Multi-Model Authentication

Who’s there? Implementing Identity Platform for iOS

Blog Entry #10

Migrate Insightly to Copper to Strengthen Your Business (2018) — Data2CRM

Automatically create documents from a template and electronically sign using eversign

40 minutes wasted

An Introduction to Git and GitHub for Beginners

Deploying AWS Lambda function using Bitbucket Pipelines

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Coding with Pixel Fix

Coding with Pixel Fix

Welcome! I am a senior Laravel developer and here will you find all sorts of information and tutorials around Laravel, PHP, and other web development languages.

More from Medium

How set up Global Helpers in Laravel in 3 easy steps.

Everything you need to know about Carbon within Laravel

Unit Testing in Laravel

Why Laravel is the Perfect Option in PHP Frameworks ?