public function validateAndReturnErrors($dataOrRequest, array $rules, array $messages = [], array $customAttributes = []) {
        $messages = Set::flatten($messages);
        if ($dataOrRequest instanceof Request) {
            $dataOrRequest = $dataOrRequest->all();
        }
        $validator = $this->getValidationFactory()->make($dataOrRequest, $rules, $messages, $customAttributes);
        if ($validator->fails()) {
            return $validator->getMessageBag()->toArray();
        }

        return [];
    }