iamproperty/laravel-multiauth

Helpers for managing multiple authentication guards in Laravel

1.1.1 2020-03-06 11:11 UTC

This package is auto-updated.

Last update: 2024-04-06 20:24:54 UTC


README

This will help automatically assigning the correct guard so that when you call Request::user() or Auth::user() there is no need to specify the guard.

Installation

Install the package using Composer.

composer install iamproperty/laravel-multiauth

Register the guard map:

class AuthServiceProvider
{
    public function boot()
    {
        // ...
        
        SetGuardHint::guardMap([
            'agent' => \MoveButler\Agent::class,
        ]);
    }
}

Register the login listener:

class EventServiceProvider
{
    protected $listen = [
        // ...
        \Illuminate\Auth\Events\Login::class => [
            \IAMProperty\MultiAuth\SetGuardHint::class,
        ],
        // ...

Register the middleware:

class Kernel extends HttpKernel
{
    protected $middlewareGroups = [
        'web' => [
            \Illuminate\Session\Middleware\StartSession::class,
            // Add after the session is started
            \IAMProperty\MultiAuth\SetGuardFromHint::class,
            // ...

Configuration

There is no need to configure anything manually, but if you want to you can publish the config file.

php artisan vendor:publish --provider="IAMProperty\MultiAuth\MultiAuthServiceProvider"