简体   繁体   中英

Laravel 5.1 redirect after auth

I am using laravel 5.1 and have a route similar to:

Route::get('/{id}/write-review', ['middleware' => 'auth', 'uses' => 'ItemController@writeReview']);

The problem I have is that when someone goes to this page (when not logged in) they get redirected to login, which is fine, but then redirected to the $redirectPath set in AuthController.php . I would like them to be redirected back to the review page.

Thanks in advance.

The intended redirect function will redirect the user to the URL they were attempting to access before being caught by the authentication filter. A fallback URI may be given to this method in case the intended destination is not available. https://laravel.com/docs/5.1/authentication#authenticating-users

 return redirect()->intended('dashboard');

I think i found the problem route {id}/write-review must be under the web middleware

  Route::group(['middleware' => ['web']], function () {
    Route::get('login', 'Auth\AuthController@getLogin');
    Route::post('login', 'Auth\AuthController@postLogin');
    Route::get('logout', 'Auth\AuthController@getLogout');

    Route::group(['middleware' => ['auth']], function () {
        Route::get('/{id}/write-review', ['uses' => 'ItemController@writeReview']);
    });
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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