Addy Developer
Addy Developer

Reputation: 1

Can I change Model User that used in auth system in laravel?

I tried to change User Model that used by default when use command php artisan ui:auth to another model but all of way to do that is not working What should to do that ? I am using laravel version 7.x

Upvotes: 0

Views: 3003

Answers (1)

Kevin
Kevin

Reputation: 193

You can have different (or as many different) models as you want for various reasons. You just need to change the relevant section in config/auth.php. I always use a Models directory, so one of the first things I do with a new app is to relocate the User model and then tell Auth where to look for it:

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

        // 'users' => [
        //     'driver' => 'database',
        //     'table' => 'users',
        // ],
    ],

You also have to update the model's use statements in your controllers if you have custom logic, but for a vanilla Laravel Auth set-up, you should be good just by changing the config.

Edit: If you do have a structure like mine (a models directory) the default App\User namespace declaration has to change on the model itself:

Change:

namespace App;

To:

namespace App\Models;

Or whatever it is that matches your structure.

Upvotes: 2

Related Questions