Support the ongoing development of Laravel.io →
Requests Validation

I can't figure how to do this. I use FormRequest in my controller so the validation happens before i enter the controller's action method. I want to edit the json responce from my Laravel API request validation. I get something like that:

{
    "name": [
        "The name field is required."
    ],
    "username": [
        "The username field is required."
    ],
    "password": [
        "The password field is required."
    ]
}

and i need to make it like that:

{
    "errors": [
        "The name field is required.",
        "The username field is required.",
        "The password field is required."
    ]
}

before it goes to the client that uses the API. Is there any way to do that?

Last updated 3 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

phasmaweb phasmaweb Joined 24 Nov 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.