How should you name your Controllers: singular or plural? With other similar questions, naming things consistently is important for code readability, compliance with standards, and avoiding errors. In this tutorial, we will cover a dozen tips for naming different things in Laravel and PHP, including Models, Controllers, Blade files, Migrations, and more.
Keep in mind that most of those are not strict rules, you can name things however you want, as long as it works. However, the problems with non-standard naming can be these:
- You may need to write additional code to configure things to work properly
- New developers on your team may need more time to understand the code
- If things are named inconsistently, other developers need more brainpower/time to decide how to name things in their code
- In some cases, it may even lead to bugs
So, I do encourage you to keep your code as close as possible to the standard naming conventions. Here are the examples.
How to Name Models in Laravel?
The rule of thumb in Laravel is to use a singular form for model names, like
Book instead of
This is because when you generate a model using
php artisan make:model, Laravel assumes that the corresponding database table will be plural.
Using English words for naming is also...