how to return different code for required errors, invalid errors and min max errors from form request ? i am using failedValidation method.
the mobile app that consumes the API need to show translated error messages and its only using the error code return by the api not the message so need to separate the code for required errors, invalid errors and min max errors and already exist errors
below is my code in form request
/**
* Handle a failed validation attempt.
*
* @param \Illuminate\Contracts\Validation\Validator $validator
* @return void
*
* @throws \Illuminate\Validation\ValidationException
*/
protected function failedValidation(Validator $validator)
{
$errors = (new ValidationException($validator))->errors();
throw new HttpResponseException(response()->json(['code'=> 'VALIDATION_ERROR','errors' => $errors
], JsonResponse::HTTP_UNPROCESSABLE_ENTITY));
}
But i need to detect whether its a required error or already exist error or in valid format error or min max error.
How can this be done?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire