Putra Fajar Hasanuddin
Putra Fajar Hasanuddin

Reputation: 1193

Laravel resetPassword() throws with "Attempt to assign property of non-object"

I want to change the password for the current user:

public function postChange(Request $request)
{
    $user = \Auth::user();

    $this->validate($request, [
        'oldpassword' => 'required',
        'password' => 'required|confirmed|min:6',
    ]);

    if (\Hash::check($request->oldpassword, $user->password)) {
        $this->resetPassword($user->email, $request->password);
    } else {
        return \Redirect::back()->withErrors('The old password is incorrect.');
    }
}

but I get this error:

ErrorException in ResetsPasswords.php line 134:

Attempt to assign property of non-object

What do I have to change to make this work?

$this->resetPassword($user->email, $request->password);

Upvotes: 1

Views: 292

Answers (1)

Joseph Silber
Joseph Silber

Reputation: 219936

You have to pass the full user object as the first argument:

$this->resetPassword($user, $request->password);

Take a look at Laravel's source.

Upvotes: 3

Related Questions