Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

kayatech's avatar

validation request

this default output

"message": "The given data was invalid.", "errors": { "email": [ "The email field is required." ] }

this default i need add one more

"success":"false", "message": "The given data was invalid.", "errors": { "email": [ "The email field is required." ] }

0 likes
2 replies
bobbybouwmann's avatar

This output is being generated in the app/Exceptions/Handler.php class in the render method. This render method class the parent method that handles the display of all exceptions in Laravel. In this case, it's a ValidationException which has its own output.

In your case, you can simply override the invalidJson method

// app/Exceptions/Handler.php

class Handler extends ExceptionHandler
{
    // Other methods

    protected function invalidJson($request, ValidationException $exception)
    {
        return response()->json([
            'success' => false,
            'message' => $exception->getMessage(),
            'errors' => $exception->errors(),
        ], $exception->status);
    }
}

Please or to participate in this conversation.