samedi 3 décembre 2016

Redirect back to requested page in laravel 5.3

I have 3 types of users as customer,retailer and admin. In the customers side they can access services without an initial login. But however there are some routes where the login is necessary as an example shoppingcart page need customer being login. I have a database char field to find the user type in the user table. And i am redirecting back to index page of different user types after a successful login. But suppose a customer that is not yet logged in to the system access services and suddenly he clicks on the route that need a authoruzation then it will redirect to login pager where user can logged in. But after that login too they are redirected back to the index page rather than the page that requested the login. How can i redirect it back to requested page. Following are the code chunks. Thank you

Web.php(only a part is shown here other customer routes are not inside the auth middleware)

Route::group(['middleware' => 'auth'], function () {

Route::get('/cart','searchController@viewCart' );
Route::get('/cart/changeStatus','searchController@changeCartStatus' );

});

login controller authenticated function

protected function authenticated($request, $user)
{
    if($user->type === 'c') {
        return redirect('/home');
    }
    else if($user->type === 'a') {
        return redirect('/admin/home');
    }
    else if($user->type === 'r') {
        return redirect('/retailer/home');
    }

}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire