Php 如何在laravel中编辑默认验证消息?
我有以下服务器验证:Php 如何在laravel中编辑默认验证消息?,php,laravel,laravel-validation,Php,Laravel,Laravel Validation,我有以下服务器验证: $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], 'pass
$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()
。返回的日志如下所示:
现在我的问题是,消息(给定的数据无效)来自哪里?我可以自定义它吗?我不知道你的目标,但如果你找到了文件。它在目录中 。\illumb\Validation\ValidationException.php 您可以编辑
\u构造
方法中提到的消息。见下例:
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;
}
我不知道你的目标,但如果你找到了文件。它在目录中 。\illumb\Validation\ValidationException.php 您可以编辑
\u构造
方法中提到的消息。见下例:
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;
}
最好对这些类型的验证使用自定义请求如果您想这样做,请确保您首先接受“application/json”您必须检查哪些规则失败,然后-最好对这些类型的验证使用自定义请求如果您想这样做,请确保您先接受“application/json”您必须检查哪些规则失败,然后-谢谢它的工作!我想在这里做一些事情,这就是为什么我问。谢谢它的工作!我想在这里做一些事情,这就是为什么我问。