php - laravel5.3中 auth middleware认证失败后的跳转地址
PHPz
PHPz 2017-04-10 17:53:29
[PHP讨论组]

在laravel5.3里 auth middleware 直接放在了illuminate里 然后如果用户未登录会执行

他默认跳转的是/login 地址 我想修改跳转地址到/user/login

5.2的话还比较能理解 5.3这边是怎样的一个实现?

PHPz
PHPz

学习是最好的投资!

全部回复(2)
PHP中文网

这个需要修改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');
}
ringa_lee

自定义redirect?

return redirect()->route('user.login');
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号