user13708919
user13708919

Reputation:

Change name of User Model in Laravel 7

I have seen an option to change the database table name from users to something else, but the model is still User in the code. For consistency I am looking to know how I can change the name of the model to something else. In my case I want to call it "Customer" with the table name of "customers".

Upvotes: 1

Views: 5639

Answers (1)

jeremykenedy
jeremykenedy

Reputation: 4275

The User model is declared in the file: config/auth.php

...


    'providers' => [
        'users' => [
            'driver' => 'eloquent',
            'model' => App\User::class,
        ],

...

To change your user model you can change the file name or make a new model and then change the declaration in config/auth.php

...


    'providers' => [
        'users' => [
            'driver' => 'eloquent',
            'model' => App\Customer::class,
        ],

...

For consistent models and migration in you can generate them both with a single artisan command:

php artisan make:model Customer --migration

This will generate a singular instance for the model name and plural for the table name.

Upvotes: 3

Related Questions