src/PeskyCMF/Traits/DataValidationHelper.php
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 [];
    }
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 [];
    }
Validate data and returm errors array if it is invalid
@param array|Request $dataOrRequest
@param array $rules
@param array $messages
@param array $customAttributes
@return array - errors