[Vuejs]-Laravel Validation works but returns 200 instead of 422

1👍

So this worked for me:

if ($exception instanceof ValidationException && $request->expectsJson()) {
    return response()->json(['message' => 'The given data was invalid.', 'errors' => $exception->validator->getMessageBag()], 422);
}

in app\Exceptions\Handler.php, render function. But I can’t still fathom what went wrong initially.

Leave a comment