Laravel Naming Conventions
Laravel is probably the most well-known PHP framework in the market today. It is used by thousands of companies and developers every day to develop all kinds of cool and exciting products.
This is why it is more important than ever to implement fairly strict naming conventions. Using naming conventions will help you and your team to keep your project and code consistent.
In this article I will cover common naming conventions for a Laravel project.
I have also included a short video explaining everything in this article.
- Routes consisting of a single word should be plural.
- Routes consisting of multiple words should be in ‘kebab-case’ and only the last word should be plural.
- Named Routes should be plural and ‘dot’ separated including the resource method.
- Controllers should be ‘singular’ and in ‘PascalCase’, suffixed by the word ‘Controller’.
- Models should be ‘singular’ and in ‘PascalCase’.
Methods (Functions) and Properties (Variables)
- Methods and Properties should be in ‘camelCase’.
- Pivot models should be ‘singular’ and in ‘PascalCase’ and in ‘alphabetical’ order.
- Pivot tables should be ‘singular’ and in ‘snake_case’ and in ‘alphabetical’ order.
- Table names should be in ‘snake_case’ and the last word should be plural.
File Names (Including blade views)
- File names should be in ‘snake_case’ and this includes the ‘blade’ view files.
- Configuration files should be in ‘snake_case’.
- Policies should be ‘singular’ and in ‘PascalCase’ (same as the Models) and suffixed with the word ‘Policy’.