我正在使用Way's Model Validation方法并将密码字段设置为between:8,20
此模型验证插件通过挂钩保存方法并在那里验证来工作。但是,我也使用以下方法来散列密码:
/**
* Dynamically hashes passwords before they enter the database
* @param string $pass Input Password
*/
public function setPasswordAttribute($pass)
{
$this->attributes['password'] = Hash::make($pass);
}
考虑到这一点,我认为当哈希方法生成一个设置字符串时,这会导致between:8,20
规则失败。
我该怎么做才能解决这个问题?
答案 0 :(得分:1)
这是模型验证的问题之一。
您需要删除mutator,而是挂钩到'creating'事件。这样,在验证发生后,密码将在保存时进行哈希处理。