Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

Singular or Plural Models? What about multiple words?

Lesson 02/38 1:37
Autoplay

Lesson Overview

In this comprehensive lesson, we'll build a complete user notification system from scratch. You'll learn how to implement database notifications, real-time updates with broadcasting, and a polished UI for displaying notifications.

Let's talk about singular vs plural in Eloquent Model.

Typically, the Model name should be singular in the make:model artisan command, like make:model Post instead of Posts. This means Laravel will try to figure out what database table to work with. The table name would be pluralized from the Model name.


If you create a Model Project with the Migration, Laravel will name the table projects.

This is a typical behavior and best practice but not a rule. If you generate Projects instead of a Project, it would work. But I don't advise and recommend such an approach. However, it is not a strict rule.


Also, let's look at the singular and plural in multiple words. For example, you have a projects table and you want to create a project type Model. But should it be ProjectType or ProjectsType? Let's generate a Model with Migration and Controller and see the names.

We have a ProjectType Model, a project_types table, and a ProjectTypeController. So, it doesn't change anything in the Controller name but adds a pluralized form in the table name.

If you have multiple words in the Camel Case, then in the snake_case form, the second word becomes plural. Again, you can overwrite it and use, for example, projects_types for the table name.

I'm not too fond of this approach and try to stick with the so-called Laravel naming and best practices.

But, finally, if your table name is entirely different from the Model name, you can always override the conventions and provide the table name in the Model.

class Role extends Model
{
protected $table = 'user_roles';
}

Comments & Discussion

AS
Abdulbasit Salah ✓ Link copied!

can we use three word? i have a model that represent the converion rate of order to point i named PointConversionRule is it a bad approach to use three word for model?

PK
Povilas Korop ✓ Link copied!

No, it's totally fine if it's still easy to find and to understand the name.

AS
Abdulbasit Salah ✓ Link copied!

thank you 🙏