Support the ongoing development of Laravel.io →
Authentication Architecture
Last updated 2 years ago.
0

Steps:

1- create myGuard.php

class myGuard extends Guard
{
    public function login(Authenticatable $user, $remember = false)
    {
        $this->updateSession($user->getAuthIdentifier(), $user->type);
        if ($remember) {
            $this->createRememberTokenIfDoesntExist($user);
            $this->queueRecallerCookie($user);
        }
        $this->fireLoginEvent($user, $remember);
        $this->setUser($user);
    }

    protected function updateSession($id, $type = null)
    {
        $this->session->set($this->getName(), $id);
        $this->session->set('type', $type);
        $this->session->migrate(true);
    }

    public function type()
    {
        return $this->session->get('type');
    }
}

2- in AppServiceProvider or new service provider or routes.php:

public function boot()
{
    Auth::extend(
        'customAuth',
        function ($app) {
            $model = $app['config']['auth.model'];
            $provider = new EloquentUserProvider($app['hash'], $model);
            return new myGuard($provider, App::make('session.store'));
        }
    );
}

3- in config/auth.php

'driver' => 'customAuth',
Last updated 9 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

rizsoft rizsoft Joined 27 Oct 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.