How to redirect user after password reset in laravel


Posted 2 months ago | by Ryan Dhungel | on Laravel  | Viewed 164 times

When a user insert new password after requesting a password reset link, he is redirected to /home. In my app there was no home page so there was an error. I want to be able to redirect user to any page i want after successful password reset. What is the best way to do that?

In laravel, reset password rules are written in ResetPasswords.php It is located in vendor/laravel/framework/src/Illuminate/Auth/ResetsPasswords.php 

 

It uses use RedirectsUsers; as you can see it in line 13.

 

If you want you can see RedirectsUsers.php which is located in vendor/laravel/framework/src/Illuminate/Auth/RedirectsUsers.php as you can see it redirects users to home by default.

 

return property_exists($this, 'redirectTo') ? $this->redirectTo : '/home';

 

The best solution here is to declare a variable in PasswordController.php

 

It is located in app/Http/Controllers/Auth/PasswordController.php

 

In PasswordController simply put the code below and modify the way you want

 

protected $redirectTo = '/pagename';

 

Replace pagename with the actual page name you want to redirect users after they successfully reset the password

 

This is how my PasswordController looks like, Here i have redirected a user to forum page after password reset:

 

<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ResetsPasswords;

class PasswordController extends Controller
{

use ResetsPasswords;

/** * Where to redirect users after password reset. * * @var string */
protected $redirectTo = 'forum';

/** * Create a new password controller instance. * * @return void */
public function __construct()
{
$this->middleware('guest');
}
}


Specials


Build Laravel React CRUD/SPA APP in 2 hours
Build Laravel React CRUD/SPA APP in 2 hours

Build Laravel React CRUD/SPA APP in 2 hours

COUPON CODE: REACTCRUD with 90% off


Laravel with React JS - Build Twitter Like Real Ti...
Laravel with React JS - Build Twitter Like Real Time Web App

Laravel with React JS - Build Twitter Like Real Time Web App

COUPON CODE: LARAVELREACT with 90% off


Learn Laravel Building Multi User Blogging Platfor...
Learn Laravel Building Multi User Blogging Platform with SEO


React Redux Firebase CRUD App with Authentication
React Redux Firebase CRUD App with Authentication

React Redux Firebase CRUD App with Authentication

COUPON CODE: RRFTEN with 86% off


Become a Master of JavaScript from Scratch in 2018
Become a Master of JavaScript from Scratch in 2018

Become a Master of JavaScript from Scratch in 2018

COUPON CODE: JSMASTERSALE with 92% off


REACT - Up and Running with React ES6 and Open Sou...
REACT - Up and Running with React ES6 and Open Source API


Sublime Text for Rapid Web Development
Sublime Text for Rapid Web Development

Sublime Text for Rapid Web Development

COUPON CODE: LEARNSUBLIME with 90% off