'Take back to login page after successfully reset his/her password in laravel 5.4

I want to redirect to login page whenever a user successfully reset his/her password in laravel 5.4.

Currently it redirects to dashboard page after successfully reset. I looked around all stuff all are saying to place
protected $redirectTo = '/home'; in protected $redirectTo = '/'; But it does not give me any solution.



Solution 1:[1]

By default Laravel authenticates the user after they reset their password. So it's impossible to redirect to the login page since only guest users can view the login page. Even if you set the $redirectTo to /login, the guest middleware would redirect the user back to /home since the user is authenticated.

If you need to prevent the user from being automatically logged in on resetting password and redirect them to the login page, you need to follow these steps.

Do the following changes in ResetPasswordController located at app/Http/Controllers/Auth.

Change the redirect path to your login page.

protected $redirectTo = '/login';

Override the resetPassword method to prevent user being logged in. Add this to the controller.

protected function resetPassword($user, $password)
{
    $user->forceFill([
        'password' => bcrypt($password),
        'remember_token' => Str::random(60),
    ])->save();
}

Add this on top

use Illuminate\Support\Str;

The original method in ResetsPasswords trait looks like this.

protected function resetPassword($user, $password)
{
    $user->forceFill([
        'password' => bcrypt($password),
        'remember_token' => Str::random(60),
    ])->save();

    $this->guard()->login($user);
}

Edit : To send a custom response on redirection you can override sendResetResponse in your controller and add any custom session/flash messages. By default laravel sets its own response on successful password reset.

protected function sendResetResponse($response)
{
    return redirect($this->redirectPath())
                        ->with('status', trans($response));
}

Solution 2:[2]

When password successfully reset. It should auto set the session/cookie as logged on user. Try to unset the session/cookie and middleware will detect that no login is happening and you should redirected to /login page after successfully reset password.

Solution 3:[3]

before

$user->forceFill(...)->save();

after

$user->fresh();

Auth::guard('web')->login($user, $user->remember_token == NULL); 

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Jesus Erwin Suarez
Solution 3 Mert Y?lmaz