Validate the model instance

@param array $rules          Validation rules
@param array $customMessages Custom error messages
@return bool
@throws InvalidModelException
352154
public function validate(array $rules = array(), array $customMessages = array()) {
        if ($this->fireModelEvent('validating') === false) {
            if ($this->throwOnValidation) {
                throw new InvalidModelException($this);
            } else {
                return false;
            }
        }

        // check for overrides, then remove any empty rules
        $rules = (empty($rules))? static::$rules : $rules;
        foreach ($rules as $field => $rls) {
            if ($rls == '') {
                unset($rules[$field]);
            }
        }

        if (empty($rules)) {
            $success = true;
        } else {
			$customMessages = (empty($customMessages))? static::$customMessages : $customMessages;

			if ($this->forceEntityHydrationFromInput || (empty($this->attributes) && $this->autoHydrateEntityFromInput)) {
				$this->fill(Input::all());
			}

			$data = $this->getAttributes(); // the data under validation

			// perform validation
			$validator = static::makeValidator($data, $rules, $customMessages);
			$success   = $validator->passes();

			if ($success) {
				// if the model is valid, unset old errors
				if ($this->validationErrors->count() > 0) {
					$this->validationErrors = new MessageBag;
				}
			} else {
				// otherwise set the new ones
				$this->validationErrors = $validator->messages();

				// stash the input to the current session
				if (!self::$externalValidator && Input::hasSession()) {
					Input::flash();
				}
			}
		}

        $this->fireModelEvent('validated', false);

	    if (!$success && $this->throwOnValidation) {
		    throw new InvalidModelException($this);
	    }

        return $success;
    }
111961
protected function validate($data, $rules=false)
    {
        if(!$rules)
        {
            $modelName = $this->modelFullName;
            $rules = $modelName::$rules;
        }
        $validator = \Validator::make($data, $rules);
        if($validator->fails()) throw new ValidationException($validator);
        return true;
    }
801335
public function runValidate(array $rules = null)
    {
        // skip validation on empty rules
        if ($rules === null) {
            return true;
        }

        $success = true;
        // list each rule as single one
        foreach ($rules as $rule) {
            // 0 = field (property) name, 1 = filter name, 2 = filter value
            if ($rule[0] === null || $rule[1] === null) {
                continue;
            }

            $propertyName = $rule[0];
            $validationRule = $rule[1];
            $validationValue = null;
            if (isset($rule[2])) {
                $validationValue = $rule[2];
            }

            // check if target field defined as array and make recursive validation
            if (Any::isArray($propertyName)) {
                $cumulateValidation = true;
                foreach ($propertyName as $attrNme) {
                    // end false condition
                    if (!$this->validateRecursive($attrNme, $validationRule, $validationValue)) {
                        $cumulateValidation = false;
                    }
                }
                // assign total
                $validate = $cumulateValidation;
            } else {
                $validate = $this->validateRecursive($propertyName, $validationRule, $validationValue);
            }

            // do not change condition on "true" check's (end-false-condition)
            if ($validate === false) {
                $success = false;
            }
        }

        return $success;
    }
572641
protected function resolve(array $data, array $rules, array $messages, array $customAttributes)
    {
        if (is_null($this->resolver)) {
            return new Validator($this->translator, $data, $rules, $messages, $customAttributes);
        } else {
            return call_user_func($this->resolver, $this->translator, $data, $rules, $messages, $customAttributes);
        }
    }
981304
public function processValidationErrors(array $validationErrors): void
    {
        if (empty($validationErrors)) {
            return;
        }

        $propertyPathGenerator = $this->propertyPathGenerator;
        foreach ($validationErrors as $i => $error) {
            $message = $error->getTranslatableMessage();
            /** @var \Symfony\Component\Validator\Violation\ConstraintViolationBuilderInterface $violationBuilder */
            $violationBuilder = $this->context->buildViolation($message instanceof Plural ? $message->plural : $message->message);
            $violationBuilder->setParameters($message->values);

            if ($propertyPathGenerator !== null) {
                $propertyPath = $propertyPathGenerator($i, $error->getTarget());
                if ($propertyPath) {
                    $violationBuilder->atPath($propertyPath);
                }
            }

            $violationBuilder->addViolation();
        }
    }
1169667
public function rule($rule, $fields, ...$params)
    {
        if (\is_callable($rule)
            && !(\is_string($rule) && $this->hasValidator($rule))
        ) {
            $name = $this->getUniqueRuleName($fields);
            $message = $params[0] ?? null;
            $this->addInstanceRule($name, $rule, $message);
            $rule = $name;
        }

        $errors = $this->getRules();
        if (!isset($errors[$rule])) {
            $ruleMethod = 'validate' . \ucfirst($rule);
            if (!\method_exists($this, $ruleMethod)) {
                throw new \InvalidArgumentException("Rule '" . $rule . "' has not been registered with " . __CLASS__ . "::addRule().");
            }
        }

        // Ensure rule has an accompanying message
        $messages = $this->getRuleMessages();
        $message = $messages[$rule] ?? self::ERROR_DEFAULT;

        // Ensure message contains field label
        if (\strpos($message, '{field}') === false) {
            $message = '{field} ' . $message;
        }

        $this->_validations[] = [
            'rule' => $rule,
            'fields' => (array) $fields,
            'params' => (array) $params,
            'message' => '{field} ' . $message,
            'skip' => self::SKIP_CONTINUE,
        ];

        return $this;
    }
467314
public function validate($model, $validators = null)
    {
        if (isset($validators) && is_array($validators)) {
            $validation = $this->validateArray($model, $validators);
        } else {
            $validation = $this->validateModel($model);
        }
        if ($validation) {
            $errors = $validation->validate($model);
            if (count($errors)) {
                throw new ValidationException($errors);
            }
        }
    }
1287260
public function getModelValidationMessages()
    {
        $optionsMessages = $this->getOption('messages');

        //if the 'rules' option was provided for this model, it takes precedent
        if (is_array($optionsMessages)) {
            return $optionsMessages;
        }

        //otherwise look for the messages as a static property on the model
        return $rules = $this->getModelStaticValidationMessages() ?: array();
    }
1259040
public function validateDataWithRules(array $data, array $validateRules, array $validateMessages = [], array $parametricConverter = [])
    {
        foreach ($validateRules as $key => $rules) {
            $value = array_key_exists($key, $data) ? $data[$key] : null;

            if (array_key_exists('nullable', $rules) && $rules['nullable'] && is_null($value)) {
                continue;
            }

            unset($rules['nullable']);

            $defaultParametricConverter = (method_exists($this, 'getParametricConverter') && is_array($this->getParametricConverter())) ? $this->getParametricConverter() : [];
            $parametricConverter = array_merge($defaultParametricConverter, $parametricConverter);
            $parameter = (array_key_exists($key, $parametricConverter)) ? $parametricConverter[$key] : $key;

            foreach ($rules as $ruleName => $ruleParameter) {
                if ($ruleName === 'callback') {
                    if (!is_callable($ruleParameter)) {
                        throw new BadMethodCallException('The reference of rule named `callback` must be a valid callable. You provided ' . $this->getValueDescription($ruleParameter) . '.');
                    }

                    call_user_func($ruleParameter, $value, InvalidRequestException::class);
                } else {
                    $method = 'check'.ucfirst(Helper::camelCase($ruleName));

                    if (!method_exists($this, $method)) {
                        throw new BadMethodCallException('Call to undefined the ' .get_class($this). '::' .$method. '() validator that associated with the `' .$ruleName. '` rule');
                    }

                    if (!$this->$method($value, $ruleParameter)) {
                        $message = isset($validateMessages[$key][$ruleName]) ? $validateMessages[$key][$ruleName] : null;

                        throw new InvalidRequestException($this->formatMessage($parameter, $ruleName, $ruleParameter, $message));
                    }
                }
            }
        }
    }
600529
public function validate(array $rules = [], array $messages = [], bool $merge = true) : bool
    {
        if ($merge) {
            $rules = array_merge($this->rules(), $rules);
            $messages = array_merge($this->defaultMessages, $this->messages(), $messages);
        }
        $rules = $this->uniqueUpdates($rules);
        $validation = LaravelValidator::make($this->input, $rules, $messages);
        if ($validation->fails()) {
            $this->validation = $validation;
            return false;
        } else {
            $this->validation = false;
            return true;
        }
    }
787856
protected function getValidatorInstance($rules, $data, $model=null)
    {
        $factory = $this->container->make('Illuminate\Validation\Factory');

        if (method_exists($this, 'validatorInstance'))
        {
            return $this->container->call(
                [$this, 'validatorInstance'],
                compact('factory')
            );
        }

        return $factory->make(
            $data, $rules, $this->customMessages(), $this->customAttributes()
        );
    }
651338
protected function validate($data, $rules)
    {
        $data = array_filter($data);

        $validator = $this->validator->make($data, $rules);

        if ($validator->fails()) {
            throw new PagSeguroException($validator->messages()->first(), 1003);
        }
    }
184514
public function validate($data, array $rules, $context = null): ValidatorInterface
    {
        return new Validator($data, $rules, $context, $this);
    }
563118
public function validate(Request $request, array $rules = [], array $messages = [], array $customAttributes = [])
    {
        $rules = array_merge_recursive(config('forum.validation.rules'), $rules);

        $validator = $this->getValidationFactory()->make($request->all(), $rules, $messages, $customAttributes);

        if ($validator->fails()) {
            throw new ValidationException($validator);
        }
    }
238160
private function createValidator(array $data, array $rules, array $messages = [], array $customAttributes = [])
    {
        return $this->getValidatorFactory()->make($data, $rules, $messages, $customAttributes);
    }
330237
public function rule(array $params)
    {
        if (isset($params['message'])) {
            $message = $params['message'];
            unset($params['message']);
        } else {
            $message = static::getRuleMessage($params[0]);
        }
        $this->_validations[] = [
            'rule' => $params[0],
            'attributes' => (array)$params[1],
            'params' => array_slice($params, 2),
            'message' => $message
        ];
        return $this;
    }
804319
protected function validateParams(array &$params, $rules = null, $clean = false)
	{

		if( ! is_null($rules) )
		{
			// init laravel validator
			$validator = $this->newValidator($params, $rules, $clean);
			$this->setValidator($validator);
		}
		$validator = $this->getValidator();

		$rules = $validator->getRules();
		

		if ($validator->fails())
		{
			// params did not pass validation rules
			
			// add errors to exception
			$this->getException()->addErrors($validator->errors()->toArray());

			return false;
		}
		else
		{
			// params passed validation rules
			return true;
		}
	}