我下面有服务器验证:
$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;
}