samedi 28 avril 2018

Laravel validate returns "error" instead of "errors"

Using laravel 5.6, I currently, I get a 422 JSON response like this when a validation error occurs using $request->validate($rules):

{
    "error": {
        "isbn": [
            "The isbn field is required."
        ],
        "price": [
            "The price field is required."
        ]
    }
}

Instead, I expect it to be:

{
    "errors": {
        "isbn": [
            "The isbn field is required."
        ],
        "price": [
            "The price field is required."
        ]
    }
}

I noticed that the defaults in the RegisterController do return the plural of error when the validator is called with return Validator::make($data, $rules)...

Why do I get the singular form with $request->validate($rules)?



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2FrhI8a
via IFTTT

Aucun commentaire:

Enregistrer un commentaire