mstnorris's avatar

Change redirect path if already logged in

When a user is logged in, and they visit the /login route (alias to /auth/login) I want to change the default redirectPath from /home to /dashboard.

I have set

protected $redirectPath = '/dashboard';

in my AuthController as I have done with the

protected $redirectTo = '/dashboard';

however this doesn't work. How should I go about this?

0 likes
3 replies
toniperic's avatar
Level 30

Correct me if I'm wrong, but that property is only used in postLogin and postRegister methods.

What you'd want to do is edit the RedirectIfAuthenticated aka guest middleware, located at app/Http/Middleware/RedirectIfAuthenticated.php and change the handle method to

public function handle($request, Closure $next)
{
    if ($this->auth->check())
    {
        return new RedirectResponse(url('/dashboard'));
    }

    return $next($request);
}
4 likes
chords's avatar

I'm changing that same line and not having any luck...

@mstnorris - it's really working for you?

Please or to participate in this conversation.