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
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.
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.
The proper naming convention for models is singular UpperCamelCase so you should name your model Access_Level
. Good luck!
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 calledaccess__levels
with 2 underscores.
There's no such thing as UpperCamelCase and lowerCamelCase, you mean PascalCase and camelCase. UpperCamelCase and lowerCamelCase is just wrong.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community