skip to Main Content

All this code works just fine except when the password is updated. I am not getting the status message that password is updated once Auth::logout() is fired and returned to the login screen. It does change the password but no message. If there is an error, it returns back and displays a sweetalert message that passwords do not match.

Controller

 public function UserUpdatePassword(Request $request)
    {
        $validateData = $request->validate([
            'oldpassword' => 'required',
            'password' => 'required|confirmed',
        ]);

        $hashedPassword = Auth::user()->password;
        if(Hash::check($request->oldpassword,$hashedPassword)){
           $user = User::find(Auth::id());
           $user->password = Hash::make($request->password);
           $user->save();

           Auth::logout(); 
           return redirect()->route('user.logout')->with('status','Password Updated Successfully');   


        } else{
            Alert::warning('Password Mismatch','Current Password Error or Password Confirm Do Not Match');
            return redirect()->back();
        }
    }

on login screen

@if (session('status'))
                    <div class="alert" role="alert" style="background-color:#C5ECEB;">
                        {{ session('status') }}
                    </div>
                @endif

2

Answers


  1. Your

    Auth::logout(); 
    

    is before showing the status;
    So If you want to show the status message, just comment logout line as follows:

    $user = User::find(Auth::id());
    $user->password = Hash::make($request->password);
    $user->save();
    return redirect()->route('user.logout')->with('status','Password Updated Successfully');   
    
    Login or Signup to reply.
  2. Put Session::put('status','Password Updated Successfully');
    before Auth::logout();

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search