Validation 如何在验证后捕获并返回Laravel控制器中的错误?

Validation 如何在验证后捕获并返回Laravel控制器中的错误?,validation,laravel-5.7,error-messaging,Validation,Laravel 5.7,Error Messaging,我正在使用此代码验证我的$request变量: $validatedData = $request->validate([ 'name' => 'string|required|max:255', 'lead' => 'nullable|string', ... ]); 在此之后,我想将错误消息作为JSON对象返回,请使用以下代码: return response()->json([ 'errors' => $validatedDa

我正在使用此代码验证我的
$request
变量:

$validatedData = $request->validate([
    'name' => 'string|required|max:255',
    'lead' => 'nullable|string',
    ...
]);
在此之后,我想将错误消息作为JSON对象返回,请使用以下代码:

return response()->json([
    'errors' => $validatedData->errors()
]);
这里说,
$ValidateData
是一个数组。没错,但我在哪里可以找到验证错误消息?我查看了官方的Laravel5.7文档,但不清楚


有什么想法吗?

如果您需要自定义错误消息,只需在laravel文档中阅读即可

我希望,我能帮你

$messages = [
    'same'    => 'The :attribute and :other must match.',
    'size'    => 'The :attribute must be exactly :size.',
    'between' => 'The :attribute value :input is not between :min - :max.',
    'in'      => 'The :attribute must be one of the following types: :values',
];

$validator = Validator::make($input, $rules, $messages);