Laravel resetPassword()抛出“尝试赋予非对象属性”

时间:2015-09-24 19:34:19

标签: php laravel laravel-5.1

我想更改当前用户的密码:

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.');
    }
}

但是我收到了这个错误:

  

ResetsPasswords.php第134行中的ErrorException:

     

尝试分配非对象的属性

我需要做些什么来改变这项工作?

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

1 个答案:

答案 0 :(得分:3)

您必须将完整的用户对象作为第一个参数传递:

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

看看https://github.com/DatabaseCleaner/database_cleaner