Save the model to the database.

Extends parent to allow automatic many-to-many relationship attachment.

@param array $options
@return bool
496383
public function save(array $options = [])
    {
        return DB::transaction(function() use ($options) {
            $result = parent::save($options);

            foreach ($this->autofilledRelations as $relationship => $relations) {
                if (!empty($relations)) {
                    $this->$relationship()->sync((array)$this->prepForSync($relations));
                }
            }

            return $result;
        });
    }
454192
public function saveAndPropagate()
	{
		if (!$this->save())
		{
			return false;
		}

		// Loop through the relationships and save
		// Both rows and models know how to save, so it doesn't matter
		// which of the two the particular relationship returned
		foreach ($this->getRelationships() as $relationship)
		{
			if (!$relationship->save())
			{
				$this->setErrors($relationship->getErrors());
				return false;
			}
		}

		return true;
	}
990033
public function save($options = TRUE)
  {
    // Update references to referenced models
    $this->_update_references();

    // Convert old bool argument to options array
    if (is_bool($options)) {
      $options = array('w' => 1);
    }
    if (isset($options['safe'])) {
      $options['w'] = (int) $options['safe']; $options['j'] = (bool) $options['safe'];
      unset($options['safe']);
    }
    if ( ! isset($options['w'])) {
      $options['w'] = $this->db()->db()->w == 0 ? 1 : $this->db()->db()->w;
    }

    // Insert new record if no _id or _id was set by user
    if( ! isset($this->_object['_id']) || isset($this->_changed['_id']))
    {
      $action = self::SAVE_INSERT;

      $this->before_save($action);

      $values = array();
      foreach($this->_changed as $name => $_true)
      {
        $values[$name] = $this->_object[$name];
      }

      if(empty($values))
      {
        throw new MongoException('Cannot insert empty array.');
      }

      $err = $this->collection()->insert($values, $options);

      if($err['err'] && (! empty($options['w']) || ! empty($options['j'])))
      {
        throw new MongoException('Unable to insert '.get_class($this).': '.$err['err']);
      }

      if ( ! isset($this->_object['_id']))
      {
        // Store (assigned) MongoID in object
        $this->_object['_id'] = $values['_id'];
        $this->_loaded = TRUE;
      }

      // Save any additional operations
      /** @todo  Combine operations into the insert when possible to avoid this update */
      if($this->_operations)
      {
        if( ! $this->collection()->update(array('_id' => $this->_object['_id']), $this->_operations))
        {
          $err = $this->db()->lastError();
          throw new MongoException('Update of '.get_class($this).' failed: '.$err['err']);
        }
      }
    }

    // Update assumed existing document
    else
    {
      $action = self::SAVE_UPDATE;

      $this->before_save($action);

      if($this->_changed)
      {
        foreach($this->_changed as $name => $_true)
        {
          $this->_operations['$set'][$name] = $this->_object[$name];
        }
      }

      if($this->_operations)
      {
        if( ! $this->collection()->update(array('_id' => $this->_object['_id']), $this->_operations))
        {
          $err = $this->db()->lastError();
          throw new MongoException('Update of '.get_class($this).' failed: '.$err['err']);
        }
      }
    }

    $this->_changed = $this->_operations = array();

    $this->after_save($action);

    return $this;
  }
1070716
public function optionsGrouped($options = []) {
		$result = $this->options($options);
		if (!empty($result)) {
			$converted = \Helper\Tree::convertByParent($result, 'parent_id');
			$result = [];
			\Helper\Tree::convertTreeToOptionsMulti($converted, 0, ['name_field' => 'name'], $result);
		}
		return $result;
	}
1098071
public function updateExisting(array $attributes, array $options = []) : bool
    {
        if (!$this->exists) {
            return false;
        }

        return $this->forceFill($attributes)->save($options);
    }
1370093
protected function saveCollection(Collection $collection, array $options = []) {
		if ($collection->isInsertForced()) {
			unset($collection->_id);
			$collection->unforceInsert();
		}
		
		$result = true;
		
		foreach ($collection as $model) {
			if (! $this->saveModel($model, $options)) {
				$result = false;
			}
		}
		
		return $result;
	}
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();
    }
416058
public static function Save ($table_name, array $values = [], array $options = []) {
		return static::GetConnection($options)->save($table_name, $values, $options);
	}
112918
public function save(array $options = array())
	{
		$validator = app('validator')->make(
			array('name' => $this->name),
			array('name' => 'required|min:1')
		);

		if($validator->passes()) {

			if (!$this->isUserUpdateSlug($options)) {
				// If user has been set slug，it do not need set slug by automatically
				$this->slug = $this->taggingUtility->normalizeAndUniqueSlug($this->name);
			}

			// $this->name = $this->taggingUtility->normalizeTagName($this->name);
			return parent::save($options);
		} else {
			throw new \Exception('Tag Name is required');
		}
	}
245788
public function save(array $options = [])
    {
        $this->validation = Arr::get($options, 'validation', $this->validation);

        if ($this->validation) {

            $attributes = $this->getAttributes();

            $validation = $this->validation($attributes);

            if ($validation instanceof MbValidation) {
                $validation->check(true);
                $attributes = $validation->getData();
            } elseif (is_array($validation)) {
                $attributes = $validation;
            }

            $this->fill($attributes);
        }

        return parent::save($options);
    }
130212
public function save($output, array $options = []) {
		$this->_image->save($output, $options);
		$this->_image = null;
		return true;
	}
580044
public function saveArray(array $entity, array $options = []) {
		$entity = $this->newEntity($entity, $options);
		return $this->save($entity, $options);
	}
228105
protected function postOptions(array $options)
    {
        $this->model = $this->app->make(
            Arr::get($options, 'model', SettingModel::class)
        );
        $this->setConnection(Arr::get($options, 'connection', null));
        $this->setTable(Arr::get($options, 'table', 'settings'));
        $this->setKeyColumn(Arr::get($options, 'columns.key', 'key'));
        $this->setValueColumn(Arr::get($options, 'columns.value', 'value'));
    }
681563
public function setOptions(array $options)
    {
        if (isset($options['on_update'])) {
            $this->autoUpdate($options['on_update']);
        } elseif (isset($options['auto_update'])) {
            $this->autoUpdate();
        }

        return parent::setOptions($options);
    }
1089753
public function save($data = null, array $options = []) {
        if ($data) {
            $this->data($data);
        }

        return $this->getRepository()->save($this, $options);
    }
1015325
public function save($entity, $options = [])
    {
        if ($this->link() !== static::LINK_KEY) {
            return true;
        }

        $name = $this->name();
        if (!isset($entity->{$name})) {
            return true;
        }
        $related = $entity->{$name};
        $result = $related->save($options);

        $keys = $this->keys();
        $from = key($keys);
        $to = current($keys);

        $conditions = [];
        if (!isset($related->{$to})) {
            throw new ORMException("The `'{$to}'` key is missing from related data.");
        }
        $conditions[$from] = $related->{$to};

        $entity->set($conditions);
        return $result;
    }
467973
protected function performSave(array $options) {

        if ($this->autoPurgeRedundantAttributes) {
            $this->attributes = $this->purgeArray($this->getAttributes());
        }

        if ($this->autoHashPasswordAttributes) {
            $this->attributes = $this->hashPasswordAttributes($this->getAttributes(), static::$passwordAttributes);
        }

        return parent::save($options);
    }