Save a record

@param  array $data
@param  array $rules
@param  array $messages
@return bool
187870
public function save(array $data = [], array $rules = [], array $messages = [])
    {
        // Validate, and if it fails abort save
        if ($this->validateBeforeSave && ! $this->validate($data, $rules, $messages)) return false;

        return $this->saveRecord($data, $rules, $messages);
    }
1203984
protected function validate_use_validator( array $data, array $rules ) {
		if ( empty( $rules ) ) {
			return;
		}

		$validator = new Validator( $data, $rules );

		$validator->labels(
			$this->fields->pluck( 'name', 'id' )->all()
		);

		if ( $validator->fails() ) {
			foreach ( $rules as $key => $rule ) {
				$this->add_error( $key, $validator->errors( $key ) );
			}
		}
	}
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;
        }
    }
508421
public function validateData(array $data, array $rules, array $messages)
    {
        if ($rules) {
            $this->customValidator->setData($data);
            $this->customValidator->setRules($rules);
            $this->customValidator->setCustomMessages($messages);

            //if the validator fails, kick back the errors
            if ($this->customValidator->fails()) {
                return implode('. ', $this->customValidator->messages()->all());
            }
        }

        return true;
    }
3276
private function recurse($method, array $data = [], array $rules = [], array $messages = [])
    {
        // Make sure method is valid
        if ( ! in_array($method, ['save', 'validate'])) return false;

        // Disable validation
        $validateBeforeSave = $this->validateBeforeSave;
        $this->validateBeforeSave = false;

        // Perform action
        $result = $this->{$method}($data, $rules, $messages);

        // Check for relationships
        $relationships = $this->getRelationships();

        // Recurse into each relationship if we can
        foreach ($relationships as $name => $type)
        {
            $subresult = $this->recurseRelationship($method, $name, $type);

            // If a relationship fails, we fail
            if ( ! $subresult) $result = false;
        }

        // Reset validation
        $this->validateBeforeSave = $validateBeforeSave;

        return $result;
    }
699183
public function validate(array $data = [], array $rules = [], array $messages = [])
    {
        $this->prepareRecord($data, $rules, $messages);

        return $this->validateRecord();
    }
12848
public function is(array $values, array $rules)
    {
        try {
            $this->execute($values, $rules);
        } catch (\Exception $ex) {
            return false;
        }

        return true;
    }
633506
public static function make($rules = [], $message = [])
    {
        if (is_null(self::$instance)) {
            self::$instance = new self($rules, $message);
        }
        return self::$instance;
    }
1238722
public function make(array $data = [],array $validationRules = [],array $filterRules = [])
    {
        $data = $this->sanitize($data);
        $this->validation_rules($validationRules);
        $this->filter_rules($filterRules);

        return $this->run($data);
    }
936826
public static function make(array $data, array $rules)
    {
        self::$validator = new V([]);
        self::$validator->labels($data);

        foreach ($rules as $rule => $columns) {
            if (is_string($columns)) {
                $columns = self::separte($columns);
            } else {
                $columns = $columns;
            }

            $value = self::getValue($rule);

            self::$validator->rule($value['rule'], $columns, $value['value']);
        }

        return new ValidationResult(self::$validator);
    }
1091187
public function validate(array $data, $rules = null, $custom = false)
    {
        if (!$custom) {
            $rules = $this->rules($rules);
        }

        return $this->validator->make($data, $rules);
    }
31488
public function check(array $data, array $messages = array())
    {

        // Merge the given messages with the set messages.
        $messages = array_merge($this->_messages, $messages);

        // Check the CSRF token if we have a session object
        if ($this->_session) {

            if (!isset($data['_token']) || $data['_token'] !== $this->_session->getToken()) {

                $this->_errors[] = $messages['csrf'];
                return false;

            }

        }

        // Loop all the set rules and validate
        foreach ($this->_rules as $key => $rules)
        {
            // If the rules are a string, break it apart
            if (is_string($rules))
                $rules = explode('|', $rules);

            // Get the data for the rule
            $input = isset($data[$key]) ? $data[$key] : null;

            // Get the type of the input
            $inputType = $this->getInputType($input);

            // Create a key for messages
            $m_key = str_replace(array('_', '-'), ' ', $key);

            // Loop through each rule and validate
            foreach($rules as $rule) {

                // Turn the rule into an array and explode if it has parameters
                $rule = strpos($rule, ':') !== false ? explode(':', $rule) : array($rule);

                // If the rule is "required", it's a built in rule
                if ($rule[0] == 'required') {

                    if (!$input || empty($input)) {

                        if (isset($messages['required.'.$key])) {
                            $message = $messages['required.'.$key];
                        } else {
                            $message = str_replace(':key', $m_key, $messages['required']);
                        }

                        $this->_errors[] = $message;

                        break;

                    }

                    continue;

                }

                // If it's not a required field we have been given null, skip it
                if (!$input || empty($input))
                    break;

                // Throw an error if we don't have a handler for the rule
                if (!isset(static::$_handlers[$rule[0]]))
                    continue;
                //throw new \Exception('m\Validator: "'.$rule[0].'" is not a valid rule.  No matching handler exists.');

                // Handle lazy loaded handlers
                if (!is_object(static::$_handlers[$rule[0]])) {
                    $handlerName = static::$_handlers[$rule[0]];
                    $handler = new $handlerName();
                    static::$_handlers[$rule[0]] = $handler;
                } else {
                    $handler = static::$_handlers[$rule[0]];
                }

                // If there are parameters, turn them into an array
                $params = (isset($rule[1])) ? explode(',', $rule[1]) : array();

                // Add the input field to the front of the params array
                array_unshift($params, $input);

                // Call the handler and pass it the parameters
                $result = call_user_func_array(array($handler, 'check'.ucfirst($inputType)), $params);

                // If the check failed, log an error and stop validating this field
                if ($result === false) {

                    // Shorthand message keys
                    $ruleFieldName      = $rule[0].'.'.$key;
                    $ruleTypeName       = $rule[0].'.'.$inputType;

                    // Determine which message is available to send
                    if (isset($messages[$ruleFieldName])) {
                        $message = $messages[$ruleFieldName];
                    } elseif (isset($messages[$ruleTypeName])) {
                        $message = $messages[$ruleTypeName];
                    } elseif (isset($messages[$rule[0]])) {
                        $message = $messages[$rule[0]];
                    } else {
                        $message = 'The :key field failed to validate.';
                    }

                    array_shift($params);

                    // Format and log the message
                    $this->_errors[] = $handler->formatMessage($message, $m_key, $params);

                    // Onto the next field
                    break;
                }
            }
        }

        // If we have errors, we failed...
        return count($this->_errors) > 0 ? false : true;
    }
210
public function forceSave(array $rules = array(),
        array $customMessages = array(),
        array $options = array(),
        Closure $beforeSave = null,
        Closure $afterSave = null
    ) {
        return $this->internalSave($rules, $customMessages, $options, $beforeSave, $afterSave, true);
    }
518165
public static function validateFiled(array $data, string $field_value, array $field_rules, array $messages = [])
    {
        $errors = [];

        foreach ($field_rules as $check => $check_value) {

            switch ($check) {

                case 'required':
                    if (!$field_value) {
                        $errors[$check] = isset($messages['required']) ? w($messages['required']) : self::$messages['required'];
                    }

                    break;

                case 'min_length':

                    if (mb_strlen($field_value) < $check_value) {
                        $errors[$check] = sprintf(isset($messages['min_length']) ? w($messages['min_length']) : self::$messages['min_length'], $check_value);
                    }

                    break;

                case 'max_length':

                    if (mb_strlen($field_value) > $check_value) {
                        $errors[$check] = sprintf(isset($messages['max_length']) ? w($messages['max_length']) : self::$messages['max_length'], $check_value);
                    }

                    break;

                case 'min':

                    if ($field_value < $check_value) {
                        $errors[$check] = sprintf(isset($messages['min']) ? w($messages['min']) : self::$messages['min'], $check_value);
                    }

                    break;

                case 'max':

                    if ($field_value > $check_value) {
                        $errors[$check] = sprintf(isset($messages['max']) ? w($messages['max']) : self::$messages['max'], $check_value);
                    }

                    break;

                case 'pattern':

                    if (!preg_match($check_value, $field_value)) {
                        $errors[$check] = $check_value;
                    }

                    break;

                case 'min_checkboxes_checked':

                    break;

                case 'max_checkboxes_checked':

                    break;

                case 'equal_to_field':

                    if (!isset($data[$check_value]) || $field_value != $data[$check_value]) {
                        $errors[$check] = sprintf(isset($messages['max']) ? w($messages['max']) : self::$messages['max'], $check_value);
                    }

                    break;

                // Is used for invisible fields, substituting captcha: if filled, it is invalid
                case 'empty':

                    if (!empty($field_value)) {
                        $errors[$check] = isset($messages['empty']) ? w($messages['empty']) : self::$messages['empty'];
                    }

                    break;

                case 'type':

                    switch ($check_value) {

                        case 'email':

                            if (!Verify::email($field_value)) {
                                $errors[$check] = isset($messages['type']) ? w($messages['type']) : self::$messages['email'];
                            }

                            break;

                        case 'number':

                            if (!is_numeric($field_value)) {
                                $errors[$check] = isset($messages['type']) ? w($messages['type']) : self::$messages['number'];
                            }

                            break;

                        case 'integer':

                            if (!\is_numeric($field_value) || !filter_var($field_value, FILTER_VALIDATE_INT)) {
                                $errors[$check] = isset($messages['type']) ? w($messages['type']) : self::$messages['integer'];
                            }

                            break;

                        case 'digits':

                            if (!ctype_digit($field_value)) {
                                $errors[$check] = isset($messages['type']) ? w($messages['type']) : self::$messages['digits'];
                            }

                            break;

                        case 'alphanum':

                            if (!ctype_alnum($field_value)) {
                                $errors[$check] = isset($messages['type']) ? w($messages['type']) : self::$messages['aphanum'];
                            }

                            break;

                        case 'url':

                            if (!filter_var($field_value, FILTER_VALIDATE_URL)) {
                                $errors[$check] = isset($messages['url']) ? w($messages['url']) : self::$messages['url'];
                            }

                            break;
                    }

                    break;
            }
        }

        return empty($errors) ? true : $errors;
    }
184514
public function validate($data, array $rules, $context = null): ValidatorInterface
    {
        return new Validator($data, $rules, $context, $this);
    }
205094
protected function doUpdateBatch($data, array $conditions)
    {
        !$this->useTransaction ?: $this->db->getTransaction(true)->start();

        try {
            $result = $this->db->getWriter()->updateBatch($this->table, $data, $conditions);
        } catch (\Throwable $e) {
            !$this->useTransaction ?: $this->db->getTransaction(true)->rollback();

            throw $e;
        }

        !$this->useTransaction ?: $this->db->getTransaction(true)->commit();

        return $result;
    }
1324214
public function store(array $data)
    {
        DB::transaction(function() use($data) {
            $model = $this->storeNotificationInstance($data);
            foreach ($data['title'] as $langId => $content) {
                $model->contents()->save($model->contents()->getModel()->newInstance([
                            'notification_id' => $model->id,
                            'lang_id'         => $langId,
                            'title'           => $content,
                            'content'         => $data['content'][$langId],
                            'subject'         => $data['subject'][$langId]
                ]));
            }
        });
    }