我下面有服务器验证。
$this->validate([
'first_name' => ['required','min:2','max:30',new PersonNameRule],
'last_name' => ['required','min:2','max:30',new PersonNameRule],
'username' => ['required','confirmed',new UsernameRule],
'password' => 'required|confirmed|min:6|max:20',
'birthdate' => ['required','date',new EligibleAgeRule(21)]
]);
在前端,我故意不通过验证和 console.log()
的错误。返回的日志如下。
现在我的问题是,哪里是 讯息 (给定数据无效) 从哪里来的?我可以自定义吗?
我不知道你的目标是什么,但如果你找到这个文件。它在目录中 .../Illuminate/Validation/ValidationException.php.
您可以编辑您在 __construct
方法。见下面的例子。
public function __construct($validator, $response = null, $errorBag = 'default') {
parent::__construct('The given data was invalid.'); //change the message here
$this->response = $response;
$this->errorBag = $errorBag;
$this->validator = $validator;
}