The correct way will be to access to MessageBag type object of the public property $validator in ValidationException. But I do it like you, after all... it's an already JSON formatted string for you to grab.
Mar 29, 2017
2
Level 7
Getting validation errors from the Validation Exception
I want to catch and handle validation errors in my own way, but I don't know how to get validation errors array from the ValidationException:
$this->validate($request, [
'name' => 'required',
'email' => 'required|email|unique:users'
]);
Lumen documentation tells us:
Should validation fail, the
$this->validatehelper will throwIlluminate\Validation\ValidationExceptionwith embedded JSON response that includes all relevant error messages.
So what is the correct way to get validation errors array? Currently, I'm using $e->getResponse()->getOriginalContent(), but I'm not sure it's the best way to do this.
Level 7
1 like
Please or to participate in this conversation.