[英]How to redirect user to different page based on the guard for multi user system?
In laravel 5.7 there is "Authenticate.php" file that looks like this: 在laravel 5.7中,“ Authenticate.php”文件如下所示:
<?php
namespace App\Http\Middleware;
use Illuminate\Auth\Middleware\Authenticate as Middleware;
class Authenticate extends Middleware
{
/**
* Get the path the user should be redirected to when they are not authenticated.
*
* @param \Illuminate\Http\Request $request
* @return string
*/
protected function redirectTo($request)
{
if (! $request->expectsJson()) {
return route('login');
}
}
}
I have set admin guard for the admin user type (auth.php): 我已经为管理员用户类型(auth.php)设置了管理员保护:
*/
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'api' => [
'driver' => 'token',
'provider' => 'users',
],
'admin' => [
'driver' => 'session',
'provider' => 'admins',
],
'admin-api' => [
'driver' => 'token',
'provider' => 'admins',
],
],
How can i get the guard type from $request, so that I can check if the $guard name is "admin" set a different redirect page. 我如何从$ request获取防护类型,以便可以检查$ guard名称是否为“ admin”,请设置其他重定向页面。 Most tutorials are not covering 5.7 version yet.
大多数教程尚未涵盖5.7版本。
Thanks a lot in advance 提前谢谢
I think I had your issue, you can follow this question and answer, I hope to help you. 我想我遇到了您的问题,您可以按照以下问答进行,希望对您有所帮助。
How to check multiple gaurd in same laravel controller OR route
如何在同一laravel控制器或路由中检查多个gaurd
https://stackoverflow.com/a/49871781/9246297
https://stackoverflow.com/a/49871781/9246297
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.