Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the Laravel naming conventions for controllers/models/views?

I remember hearing you should name your controllers, models and views in a special way. Either singular or plural. I don't remember which ones to name what though, and i can't find anything about it in the doc.

I'm guessing it's like this:

  • Controllers are plural
  • Views are plural
  • Models are singular

Am i on the right track?

I understand it's just a convention and you don't have to follow them, but i still want to know what the right way is.

like image 536
qwerty Avatar asked Sep 09 '25 10:09

qwerty


1 Answers

The convention is:

  • Model class names are singular (class Photo extends model)
  • table names are plural (select id from photos)
  • controller resource names are singular (PhotoController.php)

I couldn't find the convention for controller names defined in the documentation, but all documented examples place the controller resource name in the singular.

From the Laravel 5.5 documentation :

By convention, the "snake case", plural name of the class will be used as the table name unless another name is explicitly specified... Eloquent will assume the Flight model stores records in the flights table

like image 195
JohanTux Avatar answered Sep 11 '25 05:09

JohanTux