Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel schema builder converts tablename to lowercase

I'm just wondering why the schema builder in laravel automatically convert all camel case to lower case in table naming

E.g

Schema::create('myTable', function(Blueprint $table)
    {
        ....
    });

It creates tablename: mytable

Why is that? Is that a convention of laravel? I don't see it in the laravel docs Schema Builder page.

Thanks

like image 253
user2720708 Avatar asked Oct 20 '22 10:10

user2720708


1 Answers

It's a common practice to use snake case in table names and field names as well and it's not only related to laravel but most people follow this convention. In Laravel's old (4x) documentation, it's been mentioned that:

Note that we did not tell Eloquent which table to use for our User model. The lower-case, plural name of the class will be used as the table name unless another name is explicitly specified. So, in this case, Eloquent will assume the User model stores records in the users table. You may specify a custom table by defining a table property on your model:

class User extends Eloquent {

    protected $table = 'my_users';

}

So, yes, Laravel uses strtolower function in many places and probably this is better to follow the common convention and it's (my_table) known as snake case.

like image 137
The Alpha Avatar answered Nov 02 '22 10:11

The Alpha