在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');
}
}
}
我已经为管理员用户类型(auth.php)设置了管理员防护:
*/
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'api' => [
'driver' => 'token',
'provider' => 'users',
],
'admin' => [
'driver' => 'session',
'provider' => 'admins',
],
'admin-api' => [
'driver' => 'token',
'provider' => 'admins',
],
],
如何从$ request获取警卫类型,以便我可以检查$ guard名称是否为“ admin”,请设置其他重定向页面。大多数教程尚未涵盖5.7版本。
非常感谢
答案 0 :(得分:0)
我想我遇到了您的问题,您可以关注该问题并回答,希望对您有所帮助。
How to check multiple gaurd in same laravel controller OR route