Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

stetim94's avatar

using different model for user authentication

I want to use a different model (Member) for user authentication throughout my entire laravel application.

So the first logic step would be to make the member model authenticable:

// Member.php

use Illuminate\Foundation\Auth\User as Authenticatable;

class Member extends Authenticatable
{

    protected $table = 'members';
    protected $fillable = [
         'first_name', 'last_name', 'email', 'password'
    ];
    protected $hidden = [
        'password', 'remember_token',
    ];

}

then in auth.php:

    'defaults' => [
        'guard' => 'member',
        'passwords' => 'users',
    ],
    'guards' => [
        'web' => [
            'driver' => 'session',
            'provider' => 'users',
        ],
        'member' => [
            'driver' => 'session',
            'provider' => 'members',
        ],
    'providers' => [
        'users' => [
            'driver' => 'eloquent',
            'model' => App\Models\User::class,
        ],
        'members' => [
            'driver' => 'eloquent',
            'model' => App\Models\Member::class,
        ],

if i then create a user in tinker, the user gets created

but attempting to fill in the form at/login, i get an error: these credentials do not match our records

i came across this:

https://laravel.com/docs/5.6/authentication#adding-custom-guards

if i understand it correctly, i still use the session guard, so i don't need a custom guard?

Can someone tell me what i am missing? Why i can't login? If any further information is required, please let me know, i will gladly add it.

0 likes
5 replies
Snapey's avatar

did you hash the password in tinker?

stetim94's avatar

yes, i did:

// select * from members;
test       | test       | [email protected]    y$.RDm/rnyNGg3cIOmr71KGeI0tlwaYgmtnpF63XSsFRq6quufxaZ0y // hash of testtest

i can login perfectly fine when i change the defaults to:

'defaults' => [
        'guard' => 'web',
        'passwords' => 'users',
    ],

the User model uses the members table:

class User extends Authenticatable
{
    use Notifiable;

    protected $table = 'members';

    // fillables and hidden

}

the problem with using User class is that i can't access the additional fields and relations from the members model. Which is why i want to change web to member, that looked relatively easy, but clearly i am missing something.

I want Auth::user() and Auth::getUser() to return a Member, not User. I thought making changes in auth.php was the way to go, maybe i just have to wrong approach?

Maybe its better to add the relations to the User model? Could that be the way to go?

Snapey's avatar

Why can the users table not have the extra fields?

stetim94's avatar

that is very likely the best option, but is it still okay to ask why this approach is not working? I have a curious mind

stetim94's avatar
stetim94
OP
Best Answer
Level 1

Okay, the problem was a protected $password attribute of Member class. For the rest my approach was correct.

Please or to participate in this conversation.