iamproperty / laravel-multiauth
Helpers for managing multiple authentication guards in Laravel
1.1.1
2020-03-06 11:11 UTC
Requires
- illuminate/auth: ^5.6|^5.7|^5.8|^6.0|^7.0
Requires (Dev)
- phpunit/phpunit: ^8.0
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"