【发布时间】:2017-03-28 18:43:20
【问题描述】:
我在这个应用程序中有一个 laravel 应用程序,我有以下登录用户功能
public function login() {
try {
$inputs = Input::except('_token');
$validator = Validator::make($inputs, User::$login);
if ($validator->fails()) {
return Redirect::to('/')->with('message', 'Please Enter Valid Credentials');
} else {
$respones = \UserHelper::processLogin($inputs);
if ($respones) {
return Redirect::to('/dashboard')->with('success_message', 'Welcome to Tressly Admin Dashboard');
} else {
return Redirect::to('/')->with('message', 'Please Enter Valid Information ');
}
}
} catch (Exception $ex) {
return CommonHelper::AdminExceptions($ex);
}
}
现在,当用户注销并按下后退按钮时,浏览器会显示上一页,因为它存在于缓存中。现在在此页面上,因为用户尝试访问任何受保护的路由应用程序它显示以下错误 我想将它重定向到'/'(主路由),因为注销的用户试图访问任何保护路由,错误来了
Class App\Illuminate\Auth\Middleware\AdminAuthenticate does not exist
我做了一个自定义的Authentication Middle,中间件的handle函数是
public function handle($request, Closure $next, $guard = null) {
if (Auth::check()) {
return $next($request);
}
return redirect('/');
}
我也在 $routeMiddleware 中的 kernal.php 中注册了它
'authAdmin' => \Illuminate\Auth\Middleware\AdminAuthenticate::class,
并像
一样保护我的路线 Route::group(['middleware' => 'authAdmin'], function () {
///routes
});
有什么想法吗?
【问题讨论】: