php - laravel5.3中 auth middleware认证失败后的跳转地址
本文介绍了php - laravel5.3中 auth middleware认证失败后的跳转地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
在laravel5.3里 auth middleware 直接放在了illuminate里 然后如果用户未登录会执行
他默认跳转的是/login 地址 我想修改跳转地址到/user/login
5.2的话还比较能理解 5.3这边是怎样的一个实现?
解决方案
这个需要修改app\Exceptions\Handler.php文件,最下面有一个 unauthenticaticated
方法
/**
* Convert an authentication exception into an unauthenticated response.
*
* @param \Illuminate\Http\Request $request
* @param \Illuminate\Auth\AuthenticationException $exception
* @return \Illuminate\Http\Response
*/
protected function unauthenticated($request, AuthenticationException $exception)
{
if ($request->expectsJson()) {
return response()->json(['error' => 'Unauthenticated.'], 401);
}
// 这里的login修改为user/login
return redirect()->guest('login');
}
这篇关于php - laravel5.3中 auth middleware认证失败后的跳转地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文