Disable request validation redirect in Laravel 5.4

When making the request we should send header info.

Accept: application/json
Content-Type: application/json

That's it, now laravel will not redirect and send the error message as JSON.


You can try like this

Include use first as below in your form request

use Illuminate\Contracts\Validation\Validator;
use Illuminate\Http\Exceptions\HttpResponseException;

and then

protected function failedValidation(Validator $validator) {
        throw new HttpResponseException(response()->json($validator->errors(), 422));
    }

now if you try to validate then it will return like

{
"title": [
"The  title field is required."
]
}