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

ryank30's avatar

Table name convention

If I want to create an eloquent model for a table named "billing_accounts", how can I create it? Should I apply camel case like this? "BillingAccount"

It would be appreciated if you can let me know the laravel naming convention for this case.

0 likes
7 replies
ritey's avatar

Typically you'd use CamelCase or snakeCase. Laravel assumes Model names to match table names but you can within the model class specify the table name to override this default behaviour so BillingAccounts would then define;

protected $table = 'billing_accounts';

3 likes
ryank30's avatar

Thanks, @ritey

What you are saying is that there's no convention for more than one word table name? I have looked into the documentation and they only describe one word table name cases. ie: user. I was just hoping to see if there's any chance that I don't have to define table name by "protected $table = 'billing_accounts';" but follow Laravel's convention for my case.

Thanks again.

ritey's avatar

I personally always go with CamelCase and if the table name doesn't match i.e. it has an underscore I'll just specify it in the model itself. With existing systems(databases) this opposed to building from scratch is the only way to harness the power.

martinbean's avatar

@ryank30 Models should be singular and “studly case” (i.e. BillingAccount) and table names should be plural and snake case (i.e. billing_accounts).

6 likes
ryank30's avatar

Thanks, @ritey

@martinbean If I created a model called "BillingAccount" for the table "billing_accounts", I don't have to specify the table name? ie: protected $table = 'billing_accounts';

1 like
martinbean's avatar

@ryank30 No, but personally I like to explicitly add table names to my models. Just for clarity and to be sure.

8 likes

Please or to participate in this conversation.