我的简单验证器会让我发疯。
$data = ['dam' => 1, 'sir' => 2];
$v = Validator::make(
$data,
['dam' => 'exists:individuals,id'],
['dam.exists' => 'Object not found']
);
$validateLab = $v->validate();
dd($validateLab);
在个人表中,有一个id = 1的条目,但没有id = 2的条目。如果按原样运行代码,则显示“ true”。如果将'dam'=> 1更改为'dam'=> 2,我得到
“给定的数据无效。”在第306行 /Applications/MAMP/htdocs/mysamples/vendor/laravel/framework/src/Illuminate/Validation/Validator.php:
...
/**
* Run the validator's rules against its data.
*
* @return void
*
* @throws \Illuminate\Validation\ValidationException
*/
public function validate()
{
if ($this->fails()) {
throw new ValidationException($this);
}
}
...
为什么?为什么不返回“找不到对象”?