vendredi 29 novembre 2019

raises a response from the validator in the form of json data in laravel

I have a controller that generates json, how do I get an error message from the validator if the error message also becomes json,

$this->validate($request,[
        'product_type' => 'required',
        'product_name' => 'required|string',
        'qty' => 'required',
    ]);
 -- code for saving process here --

 return response()->json([
            'status' => 'success',
            'msg'  => 'data succesfuly added'
        ]);

and this my return in network preview

errors: {product_type: ["The Product Type name field is required."], product_name: ["The address field is required."],…}
product_name: ["The product_name field is required."]
0: "The address field is required."
qty: ["The qty field is required."]
0: "The qty field is required."


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire