I am using...
$validator = Validator::make(...)
...to validate my input. However, instead of using that method, for API purposes, I would like to make use of Laravel's Validation Exception class.
Currently, I am trying:
// Model (Not Eloquent Model)
Validator::make(...)
// Controller
try { $model->createUser(Request $request); }
catch(ValidationException $ex)
{
return response()->json(['errors'=>$ex->errors()], 422);
}
However, the validation in the model does not appear to throw any validation exceptions. I can still get the errors by using $validator->errors(). Yet, that is still defeating my purpose.
I am trying to keep really clean controllers with only try and catch statements; therefore, keeping any and all logic and out of controllers.
How can I utilize the ValidationException to do just that?