繁体   English   中英

注册后Laravel 5.1重定向无法正常工作

[英]Laravel 5.1 Redirect after Registration not working

我只想覆盖postRegister()方法,以避免Laravel在注册后自动登录用户。 所以我在AuthController.php中做了:

public function postRegister(Request $request)
{
    $validator = $this->validator($request->all());

    if ($validator->fails()) {
        $this->throwValidationException(
            $request, $validator
        );
    }

    $this->create($request->all());

    return redirect('test');
}

Laravel像我想要的那样创建没有登录的用户,问题在于重定向行。 出于某些非常奇怪的原因,始终将用户重定向到'/auth/login'路由。 我评论了所有的中间件只是为了确保不是某些中间件在进行重定向:

    protected $routeMiddleware = [
    'auth' => \CapTable\Http\Middleware\Authenticate::class,
    'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
    'guest' => \CapTable\Http\Middleware\RedirectIfAuthenticated::class,
    'activated' => \CapTable\Http\Middleware\UserActive::class,
];

我尝试了php artisan clear-compiledphp artisan cache:clearphp artisan clear:config清理所有可能的缓存或配置文件,但Laravel仍在重定向到/auth/login

在代码中进行一些调试之后,我看到它正在阅读我的新功能,它会覆盖供应商中的原始功能。

我真的没有想法,这里有人有类似的问题,或者我怎么知道这里发生了什么?

PS test只是我想要重定向用户的路由的别名。

多谢你们

尝试给出route.php中定义的确切路线

public function postRegister(Request $request) {

       // your code here

return redirect('/login'); //This is the actual route as defined and not an alias

}

如果没有,请尝试使用return Redirect::to('http://example.com/login'); 或者return Redirect::back();

问题不在后端。 我的前端(Angular.js)中有一些重定向,它覆盖了Laravel重定向。

window.location = '/auth/login';

但我学到了一个重要的教训:始终检查前端。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM