Form Request Validation in Laravel API’s
To get a proper failure response with correct status code and error messages, we have the following options.
(\Illuminate\Contracts\Validation\Validator)as an input argument. Validator object has fails method available. We can explicitly check for the failure of our validation and can send an appropriate error message with the correct HTTP Status Code.
(\Illuminate\Contracts\Validation\Validator)as an input argument. Inside this method, we can throw Validation Exception
Laravel handles all the exceptions in App\Exceptions\Handler class for us. Here inside the register method, we can capture the Validation Exception thrown by Laravel in case of Validation Failures and can send an appropriate response back to the API consumer.