MarcinOrlowski / laravel-api-response-builder

Builds nice, normalized and easy to consume REST JSON responses for Laravel powered APIs.
MIT License
720 stars 79 forks source link

Custom key for Exceptions #229

Closed pajkho closed 1 year ago

pajkho commented 2 years ago

Would be great if you could also customize the key for the exceptions. For example we would want this:

{
    "success": false,
    "code": 115,
    "locale": "sv",
    "message": "The given data was invalid.",
    "data": {
        "messages": {
            "page": [
                "The page field is required."
            ]
        }
    },
}

to become like this below. But cant find any way to achieve this. Is this possible?

{
    "success": false,
    "code": 115,
    "locale": "sv",
    "message": "The given data was invalid.",
    "errors": {
        "messages": {
            "page": [
                "The page field is required."
            ]
        }
    },
}
MarcinOrlowski commented 1 year ago

The only way to do that is to extend ResponseBuilder as documented in "Manipulating response object" chapter.