Support the ongoing development of Laravel.io →
posted 10 years ago
Eloquent
Last updated 2 years ago.
0

I have tested and you can use Snake Case or Camel Case.

So, for "access_levels" the model can be named "accessLevel.php" or "AccessLevel.php".

You can test it, by creating a new Model with any name... for example "TestSnake.php" than you can do somewhere on your application:

$test = new \TestSnake();
echo $test->getTable();

It will return "test_snakes"

And as I said, TestSnake or testSnake will both return the same.

I hope it helped.

Regards,

Robson

Last updated 2 years ago.
0

nmayer1994 said:

Laravel enforces naming conventions on its Models. If you name a Model "User", Laravel expects a "users" table in the DB.

Laravel does not necessarily enforce model names. Use the name you want and if Laravel can't determine the proper table name just use the class attribute public $table = 'some_table'; to tell Laravel which table name should use for the model.

Last updated 2 years ago.
0

robsoncombr said:

I have tested and you can use Snake Case or Camel Case.

So, for "access_levels" the model can be named "accessLevel.php" or "AccessLevel.php".

You can test it, by creating a new Model with any name... for example "TestSnake.php" than you can do somewhere on your application:

$test = new \TestSnake(); echo $test->getTable();

It will return "test_snakes"

And as I said, TestSnake or testSnake will both return the same.

I hope it helped.

Regards,

Robson

Just to be clear, only UpperCamelCase and lowerCamelCase work (but UpperCamelCase is preferred) but snake_case does NOT work as a model. If you name your model Access_Level then laravel expects a table called access__levels with 2 underscores.

0

The proper naming convention for models is singular UpperCamelCase so you should name your model Access_Level. Good luck!

0

joannahalpern said:

Just to be clear, only UpperCamelCase and lowerCamelCase work (but UpperCamelCase is preferred) but snake_case does NOT work as a model. If you name your model Access_Level then laravel expects a table called access__levels with 2 underscores.

There's no such thing as UpperCamelCase and lowerCamelCase, you mean PascalCase and camelCase. UpperCamelCase and lowerCamelCase is just wrong.

Last updated 7 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

nmayer1994 nmayer1994 Joined 26 Jun 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.