jeudi 14 septembre 2017

How to map errors to the field?

Below is my server side validation in lumen :

$rules = array(
            'prog_code' => 'required',
            'payer_id' => 'required',
        );
        $validator = \Validator::make($post, $rules);
        if (!$validator->fails()) {
            try {
                // Start Logic Here
            } catch (\Exception $e) {

            }
        } else {
            $errors = $validator->errors();
            return response()->json($errors->all());
        }

and it return error like below :

[
    "The prog code field is required.",
    "The payer id field is required.",
]

but the problem is how I map the error of which field because I want to show the error below the particular text field.

Can we customize error like below :

[
        [prog_code] => "The prog code field is required.",
        [payer_id] => "The payer id field is required.",
]



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire