Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Kumari_shwetha's avatar

I Want to display a success message after password reset.

Hi,

I modified the code such a way that , after password reset it redirects to Login page instead of 'dashboard'. But before redirects I want to display a success message to the user 'Ssucess, your password has been updated, you may login now'. How it can be done?

Auth/ResetPasswordController.php

<?php

namespace App\Http\Controllers\Auth;

use App\Setting;
use Illuminate\Support\Facades\DB;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Auth;
use App\Providers\RouteServiceProvider;
use Illuminate\Foundation\Auth\ResetsPasswords;
use Illuminate\Support\Str;
use Illuminate\Support\Facades\Hash;

class ResetPasswordController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Password Reset Controller
    |--------------------------------------------------------------------------
    |
    | This controller is responsible for handling password reset requests
    | and uses a simple trait to include this behavior. You're free to
    | explore this trait and override any methods you wish to tweak.
    |
    */

    use ResetsPasswords;

    /**
     * Where to redirect users after resetting their password.
     *
     * @var string
     */
    protected $redirectTo = '/login';

    public function __construct()
    {
        if(Auth::check() && Auth::user()->role_id == 1){
            $this->redirectTo = route('admin.dashboard');
        } elseif(Auth::check() && Auth::user()->role_id == 2){
            $this->redirectTo = route('user.dashboard');
        }

        $this->middleware('guest')->except('logout');
    }

    protected function redirectTo()
    {
        return '/user/dashboard';
    }

    public function showResetForm($token)
    {
        $config = DB::table('config')->get();
        $settings = Setting::first();

        return view('auth.passwords.reset', compact('config', 'token', 'settings'));
    }
    
    protected function resetPassword($user, $password)
    {
        $user->forceFill([
            'password' => Hash::make($password),
            'remember_token' => Str::random(60),
        ])->save();
    }

}

Is there anthing do with this function?

vendor/laravel/ui/auth-backend/ResetsPasswords.php

 protected function sendResetResponse(Request $request, $response)
    {
        if ($request->wantsJson()) {
            return new JsonResponse(['message' => trans($response)], 200);
        }
        
        return redirect($this->redirectPath())
                            ->with('status', trans($response));
        
    }

it is not working, even though it sends status with redirect path

0 likes
8 replies
Sinnbeck's avatar

Never use env() outside of config files. It will return null in production

env('GOOGLE_ENABLE', ''),
Sinnbeck's avatar

@Kumari_shwetha I suggest fixing it. Also you cannot get the user in the constructor of a controller. So all that logic won't work. Put it in middleware

Sinnbeck's avatar

Ok let's have a look. First of

But before redirects I want to display a success message to the user

If you want to display a message before redirect, you would need to change password using Javascript. If its fine that its just after the redirect, you can just use flash to show a message after redirect

https://laravel.com/docs/9.x/session#flash-data

Kumari_shwetha's avatar

@Sinnbeck return redirect($this->redirectPath()) ->with('status', trans($response));

used the same, I think session gives problem since it is redirecting to login, all the old session may be destroyed. session 'status' empty after redirecting to login.

Please or to participate in this conversation.