@param Model $model

@return void
328300
protected function saveBelongsToRelations(Model $model)
    {
        foreach ($model->getRelations() as $name => $relation) {
            if ($model->{$name}() instanceof BelongsTo && ! is_null($relation)) {
                $relation->save();
                $model->{$name}()->associate($relation);
            }
        }
    }
715152
public function setModel(\Illuminate\Database\Eloquent\Model $model) {
        $this->model = $model;
        if ($this->model instanceof ResourceInterface) {
            $this->enableAutoEagerLoading = true;
        }
    }
1213748
public function flush($model)
    {
        if (! $this->shouldMaintainIndex($model)) {
            return;
        }

        $indexColumn = $this->getIndexColumn($model);

        $this->database
            ->table($model->searchableAs())
            ->update([$indexColumn => null]);
    }
73589
public function remove(Model $model = null)
    {
        if (func_num_args() === 0) {
            $this->connection->remove($this);
        } else {
            // avoid remove empty model
            if (is_null($model)) {
                throw new \Exception('[Norm/Collection] Cannot remove null model');
            }

            $this->applyHook('removing', $model);
            $result = $this->connection->remove($this, $model);

            if ($result) {
                $model->reset();
            }

            $this->applyHook('removed', $model);
        }
    }
475045
public function setModel(Model $model)
    {
        $this->model = $model;

        $this->query->from($model->getTable());

        return $this;
    }
1163912
public function handle($model)
    {
        if (! $model -> isUserstamping() || is_null($model -> getUpdatedByColumn())) {
            return;
        }

        $model -> {$model -> getUpdatedByColumn()} = auth() -> id();
    }
844741
public function creating(Model $model)
    {
        if (! $model->created_by) {
            $model->created_by = $this->getAuthenticatedUserId();
        }

        if (! $model->updated_by) {
            $model->updated_by = $this->getAuthenticatedUserId();
        }
    }
556735
public function setModel(Model $model)
    {
        parent::setModel($model);

        if ($model->exists) {
            $this->setInstance($model);
            $this->loadRelationValues();
        }
    }
359988
public function afterDelete(Model $Model) {
		if ($this->settings[$Model->alias]['auto'] === false) {
			return;
		}
		if (!$Model->ShadowModel) {
			return;
		}
		if (isset($this->deleteUpdates[$Model->alias]) && !empty($this->deleteUpdates[$Model->alias])) {
			foreach ($this->deleteUpdates[$Model->alias] as $assocAlias => $assocIds) {
				$Model->{$assocAlias}->updateRevisions($assocIds);
			}
			unset($this->deleteUpdates[$Model->alias]);
		}
	}
1296533
public function handle($model)
    {
        if (! $model -> isUserstamping()) {
            return;
        }

        if (is_null($model -> {$model -> getCreatedByColumn()})) {
            $model -> {$model -> getCreatedByColumn()} = auth() -> id();
        }

        if (is_null($model -> {$model -> getUpdatedByColumn()}) && ! is_null($model -> getUpdatedByColumn())) {
            $model -> {$model -> getUpdatedByColumn()} = auth() -> id();
        }
    }
387356
public function deleted($model)
    {
        if (static::syncingDisabledFor($model)) {
            return;
        }

        if ($this->usesSoftDelete($model) && config('scout.soft_delete', false)) {
            $this->saved($model);
        } else {
            $model->unsearchable();
        }
    }
1231144
public function updating(Eloquent $model): void
    {
        $original = $model->getOriginal('name');
        $current = $model->getAttribute('name');

        if ($this->isRestoringModel($model)) {
            $this->acl->addRole($current);
        } else {
            $this->acl->renameRole($original, $current);
        }
    }
1354349
public static function deleteModel($model)
    {
        foreach(AnnotationManager::getPropertiesAnnotations(BeanFactory::getObjectClass($model), RelationBase::class) as $propertyName => $annotations)
        {
            if(null === $model[$propertyName])
            {
                continue;
            }
            $annotation = $annotations[0];
            Delete::parse($model, $propertyName, $annotation);
        }
    }
627720
public function deleteModel($model)
    {
        // first remove any automatically created models
        /** @var $relationField ManyToManyField */
        foreach ($model->getMeta()->localManyToMany as $name => $relationField) {
            if ($relationField->relation->through->getMeta()->autoCreated) {
                $this->deleteModel($relationField->relation->through);
            }
        }
        $this->dropTable($model->getMeta()->getDbTable());
    }
1200030
public function moveBefore($model)
    {
        if ( is_numeric($model) ) {
            $model = call_user_func("$this->ownerClassName::findOne", $model);
        }
        $parentId = $this->parentIdField ? $model->{$this->parentIdField} : 0;
        if ( $model->{$this->sortField} < 1 ) {
            $this->reorder($parentId);
            $model->refresh();
        }
        $prevIdx = $this->getMaxIdx($parentId, $model->{$this->sortField});
        if ( $model->{$this->sortField} - $prevIdx < 2 ) {
            $this->reorder($parentId);
            $model->refresh();
            $prevIdx = $this->getMaxIdx($parentId, $model->{$this->sortField});
        }
        $newIdx = $model->{$this->sortField} - floor(($model->{$this->sortField} - $prevIdx)/2);
        if ( $this->parentIdField ) {
            call_user_func("$this->ownerClassName::updateAll", [
                $this->sortField => $newIdx,
                $this->parentIdField => $parentId,
            ], [ $this->primaryKey => $this->owner->primaryKey ]);
        } else {
            call_user_func("$this->ownerClassName::updateAll",
                [ $this->sortField => $newIdx ],
                [ $this->primaryKey => $this->owner->primaryKey ]);
        }
        $this->invalidateTagDependency();
    }
595110
public function endObject(Model $model)
    {
        $this->objects[] = $this->dumpObject($model);
        $this->_fields = null;
    }
1192853
public function delete ($Model)
    {
        $entity   = $Model->getEntity();
        $entityId = $entity->getId();

        // Clear cache first
        if (isset($this->cache[$entityId])) {
            unset($this->cache[$entityId]);
        }

        $this->em->remove($entity);
        $this->em->flush();
    }