How to Name Things in Laravel

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 Books.

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...

The full tutorial [6 mins, 1008 words] is only for Premium Members

Login Or Become a Premium Member for $129/year or $29/month
What else you will get:
  • 60 courses (1084 lessons, total 42 h 44 min)
  • 80 long-form tutorials (one new every week)
  • access to project repositories
  • access to private Discord

Recent Premium Tutorials