https://dev.to/maykl_hakobyan Laravel allows the creation of form request classes for handling data validation logic. Using the make:request command of the Artisan cli creates a new class that extends the FormRequest class.
errors(); foreach ($errors->all(':key') as $message) { Arr::set($this->validationErrors, $message, $errors->get($message)); } throw new HttpResponseException(response()->json([ 'validation_errors' => $this->validationErrors ], 422)); }} 'required|string', 'user.lastname' => 'required|string|', 'user.email' => 'required|string' ]; }} Response containing validation errors {"validation_errors": {"user": {"name": ["The user.name field is required."], "email": ["The user.email field is required."] }} }