danyal14
319
2
Lumen

Lumen request error message wrapper

Posted 5 months ago by danyal14

I am trying to wrap request validation errors in custom response.

When validating request

// Since request breaks here when post is not valid, I can't capture error response.

$this->validate($request, [
            'name' => 'required',
            'link' => 'required'
        ], [
            'required' => ':attribute, is required.'
        ]);
// Actual validator response
{
    "name": [
        "name, is required."
    ],
    "link": [
        "link, is required."
    ]
}
// Actual validator response
{
    "errors": {
    "name": [
        "name, is required."
    ],
    "link": [
        "link, is required."
    ]
}
}

I tried to capture errors in BaseController to generic solution but didn't work, any suggestions?

Please sign in or create an account to participate in this conversation.