felloz
1 month ago
272
7
Laravel

Show regular validation / request errors.

Posted 1 month ago by felloz

Hello, im sending for post (axios) in a Vuejs component form some data, that im validating in the controller, but when returns the error only return the same word, not even the default errors "The given data was invalid."

What should i do to show the standard laravel errors related to each field.

in the try:

try {
        $data = request()->validate(
                [
                    'planName' => 'required|max:20|string|unique:plans,plan_name',
                    'planPrice' => 'required|numeric',
                    'maxAccounts' => 'required|integer',
                    'unlimited' => 'nullable|boolean',
                    'totalLists' => 'nullable|integer',
                    'contacts' => 'required|integer',
                    'sends' => 'required|integer'
                ]
     );

and the catch

} catch (\Exception $th) {

            return Response::json(
                array(
                    'code'      =>  301,
                    'message'   => $th->getMessage()
                ),
                301
            );
        }

Any help is appreciated.

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