I'm developing a RESTful API with Laravel 5.3, so I'm testing some functions and request with my controllers. One thing I need to do is validate the request that my user sends before add a field in my database, so, I use a custom FormRequest to validate it.
When I tested my API in Postman and send my invalid request, response redirect me to homepage. After reading documentation, I found the following statement
If validation fails, a redirect response will be generated to send the user back to their previous location. The errors will also be flashed to the session so they are available for display. If the request was an AJAX request, a HTTP response with a 422 status code will be returned to the user including a JSON representation of the validation errors.
How can I prevent this? Or there is a AJAX mode in Postman? Any suggestion?
Also this can be achieved without overriding any function. Laravel is built to support both Json
& normal pages.
Please change your settings in postman
and set Accept
to application/json
like below
Laravel is SMART ;-)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With