Laravel 5.3 身份验证路由重定向到 /

Laravel 5.3 auth routes redirecting to /

我刚刚升级到 Laravel 5.3(从 5.2),现在验证路由有问题。

我为 RegisterController 实现了所需的方法,并将 Auth::routes(); 添加到 routes/web.php。但是当我访问 /register 时,我总是被重定向到 /.

我不知道为什么,也不知道如何找出问题所在。

中间件:

protected $middlewareGroups = [
        'web' => [
            \App\Http\Middleware\EncryptCookies::class,
            \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
            \Illuminate\Session\Middleware\StartSession::class,
            \Illuminate\View\Middleware\ShareErrorsFromSession::class,
            \Illuminate\Routing\Middleware\SubstituteBindings::class,
            \App\Http\Middleware\VerifyCsrfToken::class,
        ],
        'api' => [
            'throttle:60,1',
            'bindings',
        ],
    ];

更新:找到原因了:我已经登录了,所以总是转发我。但我仍然不知道的是,它正在这样做吗?

Auth::routes() 只是一个帮手 class 可以帮助您生成用户身份验证所需的所有路由。要更改代码,您可以浏览以下链接:

// Authentication Routes...
$this->get('login', 'Auth\LoginController@showLoginForm')->name('login');
$this->post('login', 'Auth\LoginController@login');
$this->post('logout', 'Auth\LoginController@logout')->name('logout');

// Registration Routes...
$this->get('register', 'Auth\RegisterController@showRegistrationForm')->name('register');
$this->post('register', 'Auth\RegisterController@register');

// Password Reset Routes...
$this->get('password/reset', 'Auth\ForgotPasswordController@showLinkRequestForm');
$this->post('password/email', 'Auth\ForgotPasswordController@sendResetLinkEmail');
$this->get('password/reset/{token}', 'Auth\ResetPasswordController@showResetForm');
$this->post('password/reset', 'Auth\ResetPasswordController@reset');

您可能需要检查此函数 $this->get('register', 'Auth\RegisterController@showRegistrationForm')->name('register'); 以更改路径,或者它与您的中间件有关。

刚刚找到原因。

它在RedirectIfAuthenticated中间件中:

if (Auth::guard($guard)->check()) {
     return redirect('/');
}