Chron's avatar
Level 6

Is there any way to change the default `User` table that's used for Auths

What is the recommended way of changing the user table? I'm trying to make an auth page for admin, customers and companies that connects to accounts table, I modified the config/auth.php already...

Auth.php

'providers' => [
        'users' => [
            'driver' => 'eloquent',
            'model' => App\Customer::class,
        ],
        'companies' => [
            'driver' => 'eloquent',
            'model' => App\Company::class,
        ],
        'admins' => [
            'driver' => 'eloquent',
            'model' => App\Admin::class,
        ],
0 likes
4 replies
wilburpowery's avatar

After you create your providers, next step would be to create your guards for each one.

'guards' => [
    'admin' => [
            'driver'   => 'session',
         'provider' => 'admin_users',
    ],
],

Now you can just specify your guards for each login.

Auth::guard('admin')->attempt($credentials); // login the user with the admin guard.
Auth::guard('admin')->check(); // check if the user is authenticated with the admin guard.
Chron's avatar
Level 6

@WILBURPOWERY - How about the issue about the User model? What if I don't want to use that as a base user? I manage to make a separate admin dashboard but when I register/login it still request for the User model that's why I always get "table_name. users not found".

wilburpowery's avatar

That's why you provide what model you want to use in your provider.

In your case you are specifying that your admins provider should use the App\Admin model.

Chron's avatar
Level 6

@WILBURPOWERY - Yeah, I did that already but I still get the users not found error though.

Please or to participate in this conversation.