Save model to persistent state

@param \Norm\Model $model
@param array       $options

@return void
335600
public function save(Model $model, $options = array())
    {
        $options = array_merge(array(
            'filter' => true,
            'observer' => true,
        ), $options);

        if ($options['filter']) {
            $this->filter($model);
        }

        if ($options['observer']) {
            $this->applyHook('saving', $model, $options);
        }

        $modified = $this->connection->persist($this, $model->dump());
        $model->setId($modified['$id']);

        if ($options['observer']) {
            $this->applyHook('saved', $model, $options);
        }

        $model->sync($modified);
        $this->resetCache();
    }
1027614
public function model($model, array $options = [], $rules = null)
    {
        $this->setValidation($rules, isset($options['name']) ? $options['name'] : null);

        return parent::model($model, $options);
    }
560422
public static function setUploadedFile(Model $model, $attribute, $options = [])
    {
        foreach ($options as $name => $value) {
            $_FILES[$model->formName()][$name][$attribute] = $value;
        }
    }
407699
public function save(array $options = array())
    {
        $fired = $this->fires();

        $content = count($fired)
            ? str_replace([$fired['before'], $fired['after']], '', $this->content)
            : $this->content;

        $this->setAttribute('content', $content);
        $this->attributes['content'] = $content;
        parent::save($options);
    }
1278418
public function saving(Page $model)
    {
        if ($model->is_home) {
            $query = Page::where('is_home', 1);
            if ($model->id) {
                $query->where('id', '!=', $model->id);
            }
            $query->update(['is_home' => 0]);
        }
    }
481453
public function setModel(Model $model)
    {
        $this->model = $model;
        $this->fm = $this->model->loadFunctionMap();
    }
1235844
public function save(\Illuminate\Http\Request $request)
    {
        if (is_null($this->getModelForOptions())) {
            parent::save($request);
        }
    }
744235
public function afterSave(Event $event, EntityInterface $entity, ArrayObject $options): void
    {
        if (empty($entity->get('source_id'))) {
            $entity->set('source_id', $entity->get('id'));
            $this->save($entity);
        }
    }
1167900
public function save(array $options = []) {
        $saved = parent::save($options);

        array_walk($this->translations, function($translation, $locale)  {
            if(! array_filter($translation))
                return false;

            $this->newTranslation($locale, $translation)
                ->save();
        });

        return $saved;
    }
1186390
public function save(array $options = null)
    {
        try {
            parent::save($options);
        }
        catch (Exception $ex) {
            $this->throwHalcyonSaveException($ex);
        }
    }
236259
public function save(Array $options = array())
    {
        if (Config::get('bouncy::config.auto_index')) {
            $params = $this->basicElasticParams(true);

            // When creating a model, Eloquent still
            // uses the save() method. In this case,
            // the field still doesn't have an id, so
            // it is saved first, and then indexed.
            if (! isset($params['id'])) {
                $saved = parent::save($options);
                $this->index();

                return $saved;
            }

            // When updating fails, it means that the
            // index doesn't exist, so it is created.
            if (! $this->updateIndex()) {
                $this->index();
            }
        }

        return parent::save($options);
    }
1083491
public function saved(Model $model)
    {
        if ($model::$__es_enable && $model->shouldIndex())
        {
            Queue::push('Iverberk\Larasearch\Jobs\ReindexJob', $this->findAffectedModels($model));
        }
    }
848554
public function saved(Model $model)
    {
        $tags = $this->processTags(request('tags'));
        $this->syncTags($model, $tags);
    }
743823
public function hasMany($model, $options = array())
    {
        $options = static::getRelationInfo($model, $options);

        if (!isset($options['localKey'])) {
            $options['localKey'] = static::primaryKey();
        }

        if (!isset($options['foreignKey'])) {
            $options['foreignKey'] = Inflector::foreignKey(static::table());
        }

        return $options['model']::select()
            ->where("{$options['foreignKey']} = ?", $this->{$options['localKey']})
            ->mergeNextWhere();
    }
716043
public function beforeValidate(Model $model, $options = array()) {
        if (empty($this->settings[$model->alias])) {
            return true;
        }

        foreach ($this->settings[$model->alias] as $field => $rules) {
            $validations = array();

            foreach ($rules as $rule => $setting) {
                $set = $this->_defaults[$rule];

                // Parse out values
                if (!is_array($setting) || !isset($setting['value'])) {
                    $setting = array('value' => $setting);
                }

                switch ($rule) {
                    case 'required':
                        $arg = (bool) $setting['value'];
                    break;
                    case 'type':
                    case 'mimeType':
                    case 'extension':
                        $arg = (array) $setting['value'];
                    break;
                    default:
                        $arg = (int) $setting['value'];
                    break;
                }

                if (!isset($setting['rule'])) {
                    $setting['rule'] = array($rule, $arg);
                }

                if (isset($setting['error'])) {
                    $setting['message'] = $setting['error'];
                    unset($setting['error']);
                }

                unset($setting['value']);

                // Merge settings
                $set = array_merge($set, $setting);

                // Apply validations
                if (is_array($arg)) {
                    $arg = implode(', ', $arg);
                }

                $set['message'] = __d('uploader', $set['message'], $arg);

                $validations[$rule] = $set;
            }

            if ($validations) {
                if (!empty($model->validate[$field])) {
                    $currentRules = $model->validate[$field];

                    // Fix single rule validate
                    if (isset($currentRules['rule'])) {
                        $currentRules = array(
                            $currentRules['rule'] => $currentRules
                        );
                    }

                    $validations = $currentRules + $validations;
                }

                // Remove notEmpty for uploads
                if (isset($model->data[$model->alias][$field]['tmp_name']) && isset($validations['notEmpty'])) {
                    unset($validations['notEmpty']);
                }

                $this->_validations[$field] = $validations;
                $model->validate[$field] = $validations;
            }
        }

        return true;
    }
868950
public function beforeValidate(Model $model, $options = array()) {
        $default = $this->settings[$model->alias]['defaultSet'];

        if (empty($model->validate) && isset($model->validations[$default])) {
            $this->validate($model, $default);
        }

        return true;
    }
326523
public function beforeSave(Model $model, $options = array()) {
		$fields = (array)$this->__settings[$model->alias]['fields'];
		$scope = (array)$this->__settings[$model->alias]['scope'];
		$conditions = !empty($this->__settings[$model->alias]['conditions']) ? (array)$this->__settings[$model->alias]['conditions'] : array();
		$slugfield = $this->__settings[$model->alias]['slugfield'];
		$hasFields = true;

		foreach ($fields as $field) {
			if (!$model->hasField($field)) {
				$hasFields = false;
			}

			if (!isset($model->data[$model->alias][$field])) {
				$hasFields = false;
			}
		}

		if ($hasFields && $model->hasField($slugfield) && ($this->__settings[$model->alias]['overwrite'] || empty($model->id))) {
			$toSlug = array();

			foreach ($fields as $field) {
				$toSlug[] = $model->data[$model->alias][$field];
			}

			$toSlug = join(' ', $toSlug);

			$slug = Inflector::slug($toSlug, $this->__settings[$model->alias]['separator']);

			if ($this->__settings[$model->alias]['lower']) {
				$slug = strtolower($slug);
			}

			if (strlen($slug) > $this->__settings[$model->alias]['length']) {
				$slug = substr($slug, 0, $this->__settings[$model->alias]['length']);
			}

			$conditions[$model->alias . '.' . $slugfield . ' LIKE'] = $slug . '%';

			if (!empty($model->id)) {
				$conditions[$model->alias . '.' . $model->primaryKey . ' !='] = $model->id;
			}

			if (!empty($scope)) {
				foreach ($scope as $s) {
					if (isset($model->data[$model->alias][$s])) {
						$conditions[$model->alias . '.' . $s] = $model->data[$model->alias][$s];
					}
				}
			}

			$sameUrls = $model->find('all', array(
				'recursive' => -1,
				'conditions' => $conditions
			));

			$sameUrls = (!empty($sameUrls))
				? Hash::extract($sameUrls, '{n}.' . $model->alias . '.' . $slugfield)
				: array();

			if (!empty($sameUrls)) {
				if (in_array($slug, $sameUrls)) {
					$begginingSlug = $slug;
					$index = 1;

					while ($index > 0) {
						if (!in_array($begginingSlug . $this->__settings[$model->alias]['separator'] . $index, $sameUrls)) {
							$slug = $begginingSlug . $this->__settings[$model->alias]['separator'] . $index;
							$index = -1;
						}

						$index++;
					}
				}
			}

			$model->data[$model->alias][$slugfield] = $slug;
		}

		return parent::beforeSave($model);
	}