vendredi 21 juin 2019

Laravel auth not redirected to dashboard after logout and login

I have changed redirection path of users after authentication to dashboard. Its working if i manually write URL http://127.0.0.1:8000/admin and login. But From dashboard I clicked on Logout button and then I again login but page redirected to http://127.0.0.1:8000/home not dashboard. I am learning laravel so can't understand the problem, Can anyone please help me to do this. I need to redirect user to /dashboard everytime. My code is as below.

web.php

Route::get('/', function () {
return view('welcome');
});

Route::get('/admin', function () {
return view('auth.login');
});

Auth::routes();

Route::get('/dashboard', ['middleware' => 'auth', 'uses' =>'DashboardController@index']);

Route::get('/logout', 'HomeController@logout');

RedirectedIfAuthenticated.php

public function handle($request, Closure $next, $guard = null)
{
    if (Auth::guard($guard)->check()) {
        return redirect('/dashboard');
    }

    return $next($request);
}

Logout method in HomeController.php

public function logout(Request $request) {
    Auth::logout();
    Session()->flush();
    return redirect('/admin');
}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire