自发光/多认证

此包已被弃用且不再维护。未建议替代包。

Laravel 动态认证

v0.2 2019-02-24 17:22 UTC

This package is auto-updated.

Last update: 2020-01-24 20:48:07 UTC


README

介绍

Laravel 动态认证是一个允许您动态创建多个守卫的包。

安装

要安装多认证,通过 Composer 需求它

composer require autoluminescent/multiauth

Composer 完成后,运行以下命令

php artisan multiauth:install

守卫的处理基于在 config/multiauth.php 中定义的守卫和第一个 URI 段。如果找到匹配项,我们将 Auth 默认驱动设置为“匹配的守卫”,否则将默认驱动设置为“web”。

默认情况下,config/multiauth.php 配置了“web”和“admin”守卫。

Web 守卫

当没有找到/定义其他匹配项时,“web”守卫被视为默认或回退守卫。它几乎与 Laravel 的默认认证守卫相同。

默认的“web”认证路由如下

要使用“web”守卫,您只需将 web.auth 中间件添加到您的控制器或路由即可。

Admin 守卫

Admin 只是一个示例守卫,展示了如何添加其他守卫。您可以添加任意数量的守卫。

Admin 守卫的路由如下

多认证将为所有带有“admin”前缀的路由设置默认守卫为“admin”。

要使用 admin 守卫,您只需将 admin.auth 中间件添加到您的控制器或路由即可。

多认证配置

该配置包含有关如何设置守卫的基本说明。守卫中的域键基本上是匹配 URI 第一个段的标识符。因此,如果域设置为“admin”,则所有带有“admin”前缀的路由都将加载“admin”守卫。


<?php

return [

    /*
    |--------------------------------------------------------------------------
    | Multiauth Guards
    |--------------------------------------------------------------------------
    | Here you can define guards for seperate segments / domains
    */

    'guards' => [

        /*
        |--------------------------------------------------------------------------
        | Default Web Guard
        |--------------------------------------------------------------------------
        | This is the default web guard and is active for all routes except for
        | the other guard routes you define.
        |
        */

        'web' => [

            /*
            | Web guard domain should be empty.
            */
            'domain' => '',

            /*
            | Prefix for auth routes
            | Example: http://example.test/auth
            */
            'prefix' => 'auth',
            'redirect_after_login' => '/home',
            'guard_driver' => 'session',
            'provider_driver' => 'eloquent',
            'user_model' => \Autoluminescent\Multiauth\User::class,
            'password_reset_table' => 'password_resets',
            'password_reset_expires' => 60,
            'allow_registration' => true

        ],

        'admin' => [
            'domain' => 'admin',
            'prefix' => 'admin/auth',
            'redirect_after_login' => '/admin',
            'guard_driver' => 'session',
            'provider_driver' => 'eloquent',
            'user_model' => \Autoluminescent\Multiauth\User::class,
            'password_reset_table' => 'password_resets',
            'password_reset_expires' => 60,
            'allow_registration' => false,
            
            // You can replace the layout and other blade views with your custom views.
            'views' => [
				'layout' => 'multiauth::layouts.auth',
				'login' => 'multiauth::login',
			],
        ],

    ],

];

要查看实际效果,请查看以下演示仓库: Laravel 多认证演示