Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Let's avatar
Level 4

Laravel table names are plural by default

Why tables in Laravel Eloquent are by default in plural ? https://laravel.com/docs/5.1/eloquent#defining-models

Conventions want it to be in singular. http://stackoverflow.com/a/5841297/2559851

It would be better to have a general config for this.

Thank you.

0 likes
20 replies
michaeldyrynda's avatar

Laravel's convention is plural table names by default.

You can set the $table property on your models if you want something different, but honestly, it's better not to fight it.

You have a table of users not a table of user. It's documented, and the Eloquent components of the framework are built on this, and realistically, if you're going to use Eloquent you're hardly ever going to deal with table names directly, anyway.

1 like
Let's avatar
Level 4

And why didn't they followed usual conventions ?

EliasSoares's avatar

Using plural on table name makes more sense to me, since you are probably storing multiple itens there.

Imagine the table as a bag. Fill this bag with persons.

This is a bag of persons, not a bag of person.

It's just semantic.

2 likes
t0berius's avatar

Just use

protected $table = 'singular';

in your model and all will be fine :D.

5 likes
esilva88's avatar

What if i got a table like 'proprietaries'? Does Eloquent recognize it when the model is defined as 'Proprietary'?

cutups's avatar

It gets a bit odd when you want to use a table where the name would be the same if it's plural or singular though.

ex. I want to use the table Series to store a list of re-occurring events

So the name of the table would have to be seriess

thomaskim's avatar

@cutups That's not true. The plural form for "Series" is "Series" so your table name would be "series". The Pluralizer class is smart enough to know not to just add an "s" randomly.

2 likes
cutups's avatar

Thanks for that Thomas. I should have added my comment as a question instead of a statement, as I wasn't 100% sure.

martinbean's avatar

@Let There isn’t a de facto convention for singular or plural table names—there are valid arguments from both sides of the fence. But in my near-ten year career as a professional PHP developer, the majority of projects I’ve worked on and places I’ve worked at have used plural. It (and underscores) seems to be the convention in my personal experience.

If you really want to use singular table names, I actually created a package for this: https://packagist.org/packages/martinbean/eloquent-singular-table-names

1 like
jlrdw's avatar

I have seen where other frameworks do the same thing, I suspect something that kind of caught on and programmers eventually just went with the flow, I am actually used to doing it that way now.

gildniy's avatar

Laravel will know the plural and singular forms of native English words, and how to deal with them, so no worries about Property-properties conversion. And on the other side a table may be called according to it's records, which mostly is made of many lines (hence may be called in plural: a table of properties or simply $table = 'properties';)

jstnbr's avatar

@michaeldyrynda @EliasSoares Having plural names for tables makes little sense, because there are always multiple entries. That's why it's a table. So to have make every table always plural seems absurd and goes against a DRY naming concept. Adding an "S" to the end of every table you ever create seems pretty redundant. Just get rid of the "S" and call it your "user" table - makes a lot more sense.

4 likes
EliasSoares's avatar

@jstnbr How do you name a variable on your code that contains a collection of users?

I name it $users, because when I need to do a foreach, I can name the item $user. Otherwise, I'll need to name the item variable of $item, or $aux, or $anythingElseThatDoesNotExplainsWhatsOnThisVariable

I know, we almost never write down the database table names. But when I need to write it, I want a consistency on that table name and my code.

Also, what's the cost os an additional s on my tables name of a database with 1000 table? Less then 1KB of storage? I keep with the comprehensibility.

2 likes
gregrobson's avatar

FWIW I use singular as a table represents an entity (not entities). It always makes more sense to me to use singular for the joins to have

user.user_id = post.user_id
// and not
users.user_id = posts.user_id // Users do not have a user_id shared between them.

but hey, so long as whatever you do you use it consistently either works!

I feel that quoting an XKCD comic is appropriate in this instance. :) https://xkcd.com/927/

1 like
tzman's avatar

What if I have to put members in team, how do i tell lavavel not to make teams as team is itself a collection of members.

for now I'm renaming my table to teams but it does not makes sence at all :(

golee's avatar

This is one of the few things i don't like in Eloquent. SQL is not subset of English.

Snapey's avatar

@golee

call your tables whatever you like. Just specify the name in the model.

Compares to another framework where you always have to state the table name

1 like

Please or to participate in this conversation.