Skip to content
Advertisement

Laravel use Request validation with api

I’m trying to implement validation in my api like this:

JavaScript

RideUpdateRequest:

JavaScript

So how could I give a error message back in json (if the request validation fails)? Right now in postman I receive nothing back?

–EDIT–

response:

JavaScript

Could I get something like this?:

JavaScript

Advertisement

Answer

If you take a look at the FormRequest class, you’ll see a response() method defined as something like:

JavaScript

So you can either set an Accept: aplication/json request header to comply with the expectsJson condition, or force the default response behavior by sepcifying the response() method in your own RideUpdateRequest class:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement