最佳答案
我有一个 LaravelUser
模型,它有一个独特的验证规则的 username
和 email
。在我的 Repository 中,当我更新模型时,我重新验证字段,这样就不会出现所需规则验证的问题:
public function update($id, $data) {
$user = $this->findById($id);
$user->fill($data);
$this->validate($user->toArray());
$user->save();
return $user;
}
这在测试中失败了:
ValidationException: {“ username”: [“用户名已被 ]] ,“ email”: [“ email 已经被拿走了。”]}
有没有什么办法可以把这事搞定?