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

sadhakbj's avatar

Multiple user login, with same table but with different roles.

I have a base table users, which supports 2 different types of users: admin and client. I am using Zicaco Entrust package for role management.

I need different login for the admin and the client user types. Both of the users should be able to login in the system at the same time. I am unable to think what to do next.

What can be the solution for this ?

0 likes
7 replies
sadhakbj's avatar

@Agelios thank you i will check once. I had previously worked by making multiple guards using multiple tables but i am confused regarding single table.

sadhakbj's avatar
sadhakbj
OP
Best Answer
Level 17

@Agelios I followed the documentation, i created a new guard by adding it in the config/auth:


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

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

'guards' => [
        'web' => [
            'driver'   => 'session',
            'provider' => 'users',
        ],

        'front' => [
            'driver'   => 'session',
            'provider' => 'clients',
        ],

Now, i do have a controller: Front/Auth/loginController:


       if ($this->guard()->attempt(['email' => $request->email, 'password' => $request->password, 'active' => 1])) {
            dd(' i am logged in');
        }
    }

    /**
     * Front is the guard for front.
     * @return mixed
     */
    protected function guard()
    {
        return auth()->guard('front');
    }

So if I login from the backend i.e (/admin/login) and refresh here at the front, i am getting CSRF invalid message. I think this is because of session. But don't know how to solve it. Please help me. I want both of the logins at the same time.

sadhakbj's avatar

Finally the problem was solved. By making the multiple guards and respective middlewares.

1 like
heyIm's avatar

How you have resolved this issue? Why we need to create middleware?

Please or to participate in this conversation.