簡體   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