shiftechafrica/laravel-multiple-guards

此库帮助用户处理多个守卫。请阅读read me文档。

v2.0.0 2024-07-09 19:12 UTC

README

大事从细处开始


简介

此库帮助用户处理多个守卫。阅读以下内容了解如何使用它。

安装

安装laravel-multiple-guards推荐的方式是通过 Composer

# Install package via composer
composer require shiftechafrica/laravel-multiple-guards

接下来,运行Composer命令以安装shiftechafrica/laravel-multiple-guards的最新稳定版本

# Update package via composer
 composer update shiftechafrica/laravel-multiple-guards --lock

安装后,包将被自动发现。但如果需要,您也可以运行

# run for auto discovery <-- If the package is not detected automatically -->
composer dump-autoload

然后运行这个命令,以获取您自己的配置的config/laravel-multiple-guards.php

# run this to get the configuration file at config/laravel-multiple-guards.php <-- read through it -->
php artisan vendor:publish --provider="LaravelMultipleGuards\LaravelMultipleGuardsServiceProvider"

将创建一个config/laravel-multiple-guards.php文件,按照以下示例定义您的守卫。

# set all the guards to use within the system
SYSTEM_GUARDS=admin,web

用法

按照以下步骤了解如何使用laravel-multiple-guards

如何使用库

如何在控制器中使用守卫...

class HomeController extends Controller
{
    use FindGuard;
    
        /**
         * Create a new controller instance.
         *
         * @return void
         */
        public function __construct()
        {
            $this->middleware($this->setGuardMiddleware()); //@todo this sets the middleware automatically i.e auth, auth:admin that you have defined in the config/auth.php
        }
    
        /**
         * Show the application dashboard.
         *
         * @return Renderable
         */
        public function index()
        {
            return view('home');
        }
    
        /**
         * get authenticated user
         */
        public function getUser()
        {
            return $this->findGuardType()->user();
        }
    
        /**
         * logout user
         * @return RedirectResponse
         */
        public function logout()
        {
            $this->findGuardType()->logout();
            return redirect()->route('login');
        }
}

/**
 * How to get the guard name
 * authorized
*/
 return $this->findGuardType(true); //@todo this returns the guard name i.e web , admin

版本指南

安全漏洞

对于任何安全漏洞,请通过支持发送电子邮件。

许可证

此包是开源的,受MIT许可证许可。