A 422 Error is thrown when Laravel validates your Request data and the data is wrong, invalid or not processable.
If you are validating your data in an extra Request class, you can add a message
method to override the error messages (further info here):
/**
* Get the error messages for the defined validation rules.
*
* @return array
*/
public function messages()
{
return [
'body.required' => 'A message is required',
];
}
If you are validating the data inside your Controller through $request->validate(...)
, you need to create an own Validator class inline with a messages argument (further info here):
$messages = [
'required' => 'The :attribute field is required.',
];
$validator = Validator::make($input, $rules, $messages);