更新时间:2023-11-17 13:14:58
您必须覆盖 failedValidation()
方法,并使用所需的响应发出异常.
因此,您需要在 RequestForm 类中使用Illuminate\Contracts\Validation\Validator
和Illuminate\Http\Exceptions\HttpResponseException
,并覆盖failedValidation()
方法:
You have to override the failedValidation()
method and issue the exception with the response what you want.
So, you need to use Illuminate\Contracts\Validation\Validator
and Illuminate\Http\Exceptions\HttpResponseException
in the RequestForm class, and override the failedValidation()
method:
protected function failedValidation(Validator $validator) {
throw new HttpResponseException(response()->json($validator->errors()->all(), 422));
}