扫码关注官方订阅号
在laravel5.3里 auth middleware 直接放在了illuminate里 然后如果用户未登录会执行
他默认跳转的是/login 地址 我想修改跳转地址到/user/login
5.2的话还比较能理解 5.3这边是怎样的一个实现?
学习是最好的投资!
这个需要修改app\Exceptions\Handler.php文件,最下面有一个 unauthenticaticated 方法
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'); }
自定义redirect?
return redirect()->route('user.login');
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
这个需要修改app\Exceptions\Handler.php文件,最下面有一个
unauthenticaticated方法自定义redirect?