dev-techguy / laravel-multiple-guards
这个库可以帮助你处理多个守卫。阅读README以了解如何使用。
v1.1.9
2023-02-24 12:59 UTC
Requires
- illuminate/support: ^5.7|^5.8|^6.0|^7.0|^8.0|^9.0|^10
README
简介
这个库可以帮助你处理多个守卫。阅读以了解如何使用。
安装
安装laravel-multiple-guards的推荐方法是使用Composer。
# Install package via composer
composer require dev-techguy/laravel-multiple-guards
接下来,运行Composer命令以安装最新稳定的dev-techguy/laravel-multiple-guards版本。
# Update package via composer
composer update dev-techguy/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
版本指南
安全漏洞
对于任何安全漏洞,请发送电子邮件至Vincent Ososi。
许可证
此包是开源的,受MIT许可证许可。