Obtaining validation failure errors in a form request
I have a client that's getting a 422 response from a form request validation failure. The client is remote and I can't see the response body they receive, so I'm trying to log why the request is failing on the server side. Looking at the form request docs, I see that there is a withValidator hook that allows me to inspect the validation rules before they are applied. What I want is something similar but that occurs after evaluation, but before the response is delivered back to the client so that I can log the errors and find out what it's up to.
If you want to temporarily target a specific Form Request; you can use the failedValidation method in that specific Form Request class:
protected function failedValidation(Validator $validator)
{
// you have an instance of the validator from which you can get the errors, e.g.
\Log::debug('Validation Failed', $validator->errors());
parent::failedValidation($validator);
}