AmirAmir2011
AmirAmir2011

Reputation: 23

standard way for naming tables and model

I want to naming tables in my project, I have a table for tour services.

What is the best naming method for table and model? camelCase, snake_case or PascalCase (upper camelCase)?

is it right for table 'tourServices' and for model 'TourService'?

Upvotes: 2

Views: 321

Answers (2)

Kenny Horna
Kenny Horna

Reputation: 14241

For table names: Snake Case and the name in plural (if pivot table you could use the singular version of each model and order it alphabetically):

'tour_services' // regular table
'users' // regular table
'roles' // regular table
'role_user' // <-- pivot table

For model names: Pascal Case (also in singular)

'TourService'
'User'
'Role'

Check this other answer that touches this subject. Also, check this other post that talks about case styles.

Upvotes: 7

nakov
nakov

Reputation: 14268

You can name the model and let Laravel name the table for you. Tables are mostly named using snake_case, and plural from the model, but you can just run this, and Laravel will do the rest:

php artisan make:model TourService -m

The -m flag creates a migration with the name of the table based on the given model.

But then again, I am not sure that I will go with a Service name in the model, maybe just a Tour is a good name for the model, I don't know what is the context of the model.

Upvotes: 0

Related Questions