lundi 23 mai 2016

Laravel, Append Values to Custom Request Error Message

I am building an API, the desired output when there is an error is as follows:

{
    "success": false,
    "messages" : [
        {
            "field is missing for example",
            ....
        }
    ]
}

I have a custom request called when from the controller as follows:

public function store(CoverageValueRequest $request, CoverageValueManager $manager){
    $manager->create($request);
    return response()->json(['success' => $manager->isSuccessful(), 'message' => $manager->getErrorMessage()]);
}

if the CoverageValueRequest has an error it would through something similar to this:

[
{
    "series.0.values.0.cells": [
        "The series.0.values.0.cells field is required when none of series.0.values.0.wifi are present."
    ],
    "series.0.values.0.wifi": [
        "The series.0.values.0.wifi field is required when none of series.0.values.0.cells are present."
    ]
}
]

How can I modify the error outcome of the custom request to follow the first posted structure.

Thanks in advance.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1TrrnS6
via IFTTT

Aucun commentaire:

Enregistrer un commentaire