Laravel 5 - 当前用户密码的验证器

Laravel 5 - validator for current user password

我有密码更改表单,其中有两个字段:old_passwordnew_password

我受困于旧密码验证程序,我是这样做的:

Validator::extend('old_password', function($attribute, $value) use ($user) {
    return $user->password === Hash::make($value);
});

但是 Hash::make($value) 总是用相同的 $value 生成不同的结果。

如何让验证器匹配当前用户密码?

您应该改用 Hash::check( $plaintext, $hashed )

return Hash::check( $value, $user->password );