Save or update the model in the database.

@param mixed $identifier
@param array $attributes

@return Eloquent
8781
public function update($identifier, array $attributes = [])
    {
        return $this->mediator->transform($this->mediator(func_get_args()))->first();
    }
957077
protected function updateInternal($attributes = null)
    {
        if (!$this->beforeSave(false)) {
            return false;
        }
        
        $values = $this->getDirtyAttributes($attributes);
        
        if (empty($values)) {
            $this->afterSave(false, $values);
            
            return 0;
        }
        
        $condition = $this->getOldPrimaryKey(true);
        $lock = $this->optimisticLock();

        if ($lock !== null) {
            if (!isset($values[$lock])) {
                $values[$lock] = $this->$lock + 1;
            }

            $condition[$lock] = $this->$lock;
        }

        // We do not check the return value of update() because it's possible
        // that it doesn't change anything and thus returns 0.
        $rows = static::getBucket()->update($values, $condition);

        if ($lock !== null && !$rows) {
            throw new StaleObjectException('The object being updated is outdated.');
        }
        
        if (isset($values[$lock])) {
            $this->$lock = $values[$lock];
        }
        
        $changedAttributes = [];
        
        foreach ($values as $name => $value) {
            $changedAttributes[$name] = $this->getOldAttribute($name);
            $this->setOldAttribute($name, $value);
        }
        
        $this->afterSave(false, $changedAttributes);
        
        return $rows;
    }
1099349
public function save($identifier, $contents)
	{
		// get the language and the identifier
		list ($language, $identifier) = explode(DS, $identifier, 2);
		$identifier = basename($identifier, '.db');

		// prep the contents
		$this->prep_vars($contents);
		$contents = serialize($contents);

		// update the config in the database
		$result = \DB::update($this->table)->set(array('lang' => $contents, 'hash' => uniqid()))->where('identifier', '=', $identifier)->where('language', '=', $language)->execute();

		// if there wasn't an update, do an insert
		if ($result === 0)
		{
			list($notused, $result) = \DB::insert($this->table)->set(array('identifier' => $identifier, 'language' => $language, 'lang' => $contents, 'hash' => uniqid()))->execute();
		}

		return $result === 1;
	}
738735
public function update(string $index, array $attributes, array $toMany): int
    {
        $updated        = 0;
        $pkName         = $this->getModelSchemas()->getPrimaryKey($this->getModelClass());
        $filters        = [
            $pkName => [
                FilterParameterInterface::OPERATION_EQUALS => [$index],
            ],
        ];
        $allowedChanges = $this->filterAttributesOnUpdate($attributes);
        $saveMain       = $this
            ->createBuilder($this->getModelClass())
            ->updateModels($allowedChanges)
            ->addFiltersWithAndToTable($filters);
        $saveMain       = $this->builderSaveResourceOnUpdate($saveMain);
        $saveMain->getSQL(); // prepare

        $this->clearBuilderParameters()->clearFetchParameters();

        $this->inTransaction(function () use ($saveMain, $toMany, $index, &$updated) {
            $updated = $saveMain->execute();

            $builderHook = Closure::fromCallable([$this, 'builderSaveRelationshipOnUpdate']);
            foreach ($toMany as $relationshipName => $secondaryIds) {
                $connection = $saveMain->getConnection();

                // clear existing
                $this->builderCleanRelationshipOnUpdate(
                    $relationshipName,
                    $this
                        ->createBuilderFromConnection($this->getConnection(), $this->getModelClass())
                        ->clearToManyRelationship($relationshipName, $index)
                )->execute();

                // add new ones
                $updated   += $this->addInToManyRelationship(
                    $connection,
                    $index,
                    $relationshipName,
                    $secondaryIds,
                    $builderHook
                );
            }
        });

        return (int)$updated;
    }
248163
public function update($id, array $attributes)
    {
        $model = $this->model->findOrFail($id);

        $this->validation()->validate('update', array_merge($attributes, [$this->model->getKeyName() => $id]));

        $model->fill($attributes);

        $model->save();

        return $model;
    }
365909
public function update(array $attributes, $id)
    {
        $this->applyScope();

        $model = $this->model->findOrFail($id);
        $model->fill($attributes);
        $model->save();

        $this->applyAfterSave($model);

        $this->resetModel();

        event(new RepositoryEntityUpdated($this, $model));

        return $this->parserResult($model);
    }
666635
public function update(array $attributes)
    {
        return $this->validate($attributes) ? (boolean) Language::where('id', $attributes['id'])->update($attributes) : false;
    }
967282
public function retrieveById($identifier) {
        if (!$this->isValidIdentifierValue($identifier)) {
            return null;
        }
        /** @var RecordInterface $user */
        $user = $this->createEmptyUserRecord()->fromPrimaryKey($identifier, [], $this->getRelationsToFetch());

        return $this->validateUser($user, null);
    }
1013608
public function update($attributes)
    {
        $this->attributes = array_merge($this->attributes, array_filter($attributes, function ($attribute) {
            return ! is_null($attribute);
        }));

        return $this;
    }
294556
public function addRemoteIdentity($provider, $identifier)
    {
        //! @todo delete all by provider and identifier
        $model = new UserRemoteIdentity();
        $model->setAttributes([
            'user_id' => $this->id,
            'provider' => $provider,
            'identifier' => $identifier,
        ], false);

        return $model->save();
    }
14201
protected function resolveModelAndIdentifier($model, $identifier)
    {
        $resolve = new ResolveComponentModelIdentifier($model, $identifier);

        return $this->getComponentDataResolver()->resolveComponentData($resolve);
    }
935994
public function update(array $attributes)
    {
        $this->query->type = QueryType::$UPDATE;
        $this->query->updateAttributes = $attributes;
        return QueryExecutor::prepare($this->db, $this->query)->execute();
    }
551937
public function update($id = null, $attributes = [])
    {
        // Check the ID
        if (!isset($id)) {
            throw new \InvalidArgumentException('Undefined ID', 400);
        }

        // Set the attributes
        $attributes = (!empty($attributes))? $attributes : $this->app->request->input();

        // Update the record
        $result = $this->model->update($id, $attributes);

        // Return results
        return [
            'success' => true,
            'id' => $id,
            'data' => $result
        ];
    }
839939
public function update(Identifiable $model, array $newAttributes)
    {
        $this->checkIsModel($model);

        $this->validate($newAttributes, 'update');

        if (!$this->fill($model, $newAttributes)) {
            return false;
        }

        $this->callBeforeListeners('update', [$model, $newAttributes]);

        $this->save($model);

        $this->callAfterListeners('update', [$model, $newAttributes]);

        return true;
    }
335307
private function updateHasMany($id, $attributes)
    {
        // Return if the ID is invalid, or attributes is not an array
        if (!isset($id) || !isset($attributes) || empty($attributes)) {
            return $this;
        }

        // Return if there are no relationships of that type
        if (!isset($this->relationships['hasMany']) || empty($this->relationships['hasMany'])) {
            return $this;
        }

        // Sync each relationship
        foreach ($this->relationships['hasMany'] as $join) {

            // The sync option has to be set, the related attribute an array
            if (isset($join['sync']) && is_array($join['sync']) && isset($attributes[$join['alias']]) && is_array($attributes[$join['alias']])) {

                // Get related elements
                $related = $attributes[$join['alias']];

                // Write trough the model
                if (isset($join['model'])) {

                    // Get or instance the related model
                    if (isset($this->models) && isset($this->models[$join['model']])) {
                        $instance = $this->models[$join['model']];
                    } else {
                        $instance = new $join['model'];
                    }

                    // Delete elements if the overwrite option was set
                    if (in_array('overwrite', $join['sync'])) {
                        $results = $instance->where($join['foreignKey'], $id, '=', $instance->getTable())->limit($join['limit'])->get();
                        if ($results) {
                            foreach ($results as $result) {
                                $instance->destroy($result[$instance->getPrimaryKey()]);
                            }
                        }
                    }

                    // Iterate related elements
                    foreach ($related as $value) {

                        // Add the foreign key
                        $value[$join['foreignKey']] = $id;

                        // Insert elements whitout ID
                        if (in_array('insert', $join['sync']) && !isset($value['id'])) {
                            $instance->create($value);
                        }

                        // Update elements width ID
                        if (in_array('update', $join['sync']) && isset($value['id'])) {

                            // Check if the existing element belongs to this record
                            $current = $instance->find($value['id']);
                            if ($current && isset($current[$join['foreignKey']]) && $current[$join['foreignKey']] == $id) {
                                $instance->update($value['id'], $value);
                            }
                        }
                    }
                }

                // Write trough database
                if (!isset($join['model'])) {

                    // Delete elements if the overwrite option was set
                    if (in_array('overwrite', $join['sync'])) {
                        $results = $this->db()->table($join['table'])->where($join['foreignKey'], $id)->limit(100)->get();
                        if ($results) {
                            $ids = array_diff(array_column($results, 'id'), array_column($related, 'id'));
                            $this->db()->table($join['table'])->whereIn('id', $ids)->delete();
                        }
                    }

                    // Iterate related elements
                    foreach ($related as $value) {

                        // Leave only writable fields
                        $fields = array_intersect_key($value, array_flip($join['columns']));

                        // Add the foreign key
                        $fields[$join['foreignKey']] = $id;

                        // Insert elements whitout ID
                        if (in_array('insert', $join['sync']) && !isset($value['id'])) {
                            $this->db()->table($join['table'])->insert($fields);
                        }

                        // Update elements width ID
                        if (in_array('update', $join['sync']) && isset($value['id'])) {

                            // Check if the existing element belongs to this record
                            $current = $this->db()->table($join['table'])->where('id', $value['id'])->limit(1)->getOne();
                            if ($current && isset($current[$join['foreignKey']]) && $current[$join['foreignKey']] == $id) {
                                $this->db()->table($join['table'])->where('id', $value['id'])->update($fields);
                            }
                        }
                    }
                }
            }
        }

        // Return model instance
        return $this;
    }
1351362
public static function load(string $attributes, array $keys = []): IdentificatorInterface
    {
        $values = explode(";", $attributes);
        $attributes = [];
        foreach ($keys as $k => $key) {
            if (array_key_exists($k, $values)) {
                $attributes[$key] = $values[$k];
            }
        }

        return new Identificator($attributes);
    }
799659
public function update($attributes)
    {
        if (!empty($attributes)) {
            foreach ($attributes as $attribute => $value) {
                $this->set($attribute, $value);
            }
        }

        return $this;
    }