Run transforms on a single model

@param  Model      $model
@return Model|void
187236
protected function runSerializeTransformsOnModel(Model $model)
    {
        // Loop through all the transform functions
        foreach ($this->serialize_transforms as $transform) {

            // Call the transform and if nothing is retuned, return nothing. This will
            // be used by runSerializeTransformsOnCollection() to filter out models.
            if (!$model = call_user_func($transform, $model)) {
                return;
            }
        }

        // Return the transformed model
        return $model;
    }
1129534
public function clearCache(Model $model) {
        if ($this->_cached) {
            foreach ($this->_cached as $key => $value) {
                $this->deleteCache($model, $key);
            }
        }

        return Cache::clear(false, $this->settings[$model->alias]['cacheConfig']);
    }
813460
protected function doPatch($model, $patch)
    {
        $op = isset($patch['op']) ? $patch['op'] : 'replace';
        switch ($op) {
            case 'remove':
                $model->{$patch['field']} = null;
                break;
            case 'move':
                $model->{$patch['field']} = $model->{$patch['from']};
                $model->{$patch['from']} = null;
                break;
            case 'copy':
                $model->{$patch['field']} = $model->{$patch['from']};
                break;
            default:
                $model->{$patch['field']} = $patch['value'];
                break;
        }
    }
150410
protected function setModelForElements(Model $model)
    {
        $this->getElements()->each(function ($element) use ($model) {
            $element = $this->getElementContainer($element);

            if ($element instanceof WithModelInterface) {
                $element->setModel($model);
            }
        });

        return $this;
    }
247566
public function transform(Arrayable $model)
    {
        $model = array_reduce($this->transformers, function ($carry, IDataTransformer $transformer) {
            return collect($transformer->transform($carry));
        }, $model);
        return parent::transform($model);
    }
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]);
		}
	}
120578
public static function import(Model $model)
    {
        Utils\Utils::arrayPathSet(self::$models, self::getPath($model), $model);
    }
612064
protected function invalidate(Model $model): void
    {
        $key = $this->prefix . ":" . $model->getKey();
        if ($this->cacheRepository->has($key)) {
            $this->cacheRepository->forget($key);
        }
        $this->cacheRepository->forget("$this->prefix.:all");
    }
235540
public function moveAfter($model)
    {
        if ( ! $model ) {
            $this->moveFirst();
            return;
        }
        if ( is_numeric($model) ) {
            $model = call_user_func("$this->ownerClassName::findOne", $model);
        }
        $parentId = $this->parentIdField ? $model->{$this->parentIdField} : 0;
        if ( $model->{$this->sortField} == $this->defaultSortVal ) {
            $this->reorder($parentId);
            $model->refresh();
        }
        $nextIdx = $this->getMinIdx($parentId, $model->{$this->sortField});
        if ( $nextIdx - $model->{$this->sortField} < 2 ) {
            $this->reorder($parentId);
            $model->refresh();
            $nextIdx = $this->getMinIdx($parentId, $model->{$this->sortField});
        }
        $newIdx = $model->{$this->sortField} + floor(($nextIdx - $model->{$this->sortField})/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();
    }
556735
public function setModel(Model $model)
    {
        parent::setModel($model);

        if ($model->exists) {
            $this->setInstance($model);
            $this->loadRelationValues();
        }
    }
1195509
private function prepare(Model $model): Model
    {
        if ($model->usesTimestamps()) {
            $time = $model->freshTimestamp();

            $updatedAtColumn = $model->getUpdatedAtColumn();

            // If model has updated at column and not manually provided.
            if ($updatedAtColumn && null === $model->{$updatedAtColumn}) {
                $model->setUpdatedAt($time);
            }

            $createdAtColumn = $model->getCreatedAtColumn();

            // If model has created at column and not manually provided.
            if ($createdAtColumn && null === $model->{$createdAtColumn}) {
                $model->setCreatedAt($time);
            }
        }

        return $model;
    }
1180007
private function update($model)
    {
        $attrs = $this->getMutableAttributes($model);
        $values = array_values($attrs);
        $values[] = $model->{$this->key};
        $this->db
            ->connect()
            ->update($this->table, array_keys($attrs))
            ->where($this->key . ' = ?')
            ->execute($values);
    }
919865
public function setModel(Model $model)
    {
        if (strpos($this->originalName, '.') !== false) {
            $parts = explode('.', $this->originalName);
            $name = array_pop($parts);

            while ($parts) {
                $part = array_shift($parts);
                $relation = $model->getAttribute($part);

                if ($relation instanceof Model) {
                    $model = $relation;
                    $this->setName($name);
                }
            }
        }

        return parent::setModel($model);
    }
1327210
public function setModel(Model $model)
    {
        if (($content = $this->getContent()) instanceof WithModelInterface) {
            $content->setModel($model);
        }

        return $this;
    }
475045
public function setModel(Model $model)
    {
        $this->model = $model;

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

        return $this;
    }
872906
protected function run($models)
    {
        $models = collect($models);
        if ($models->count() > 0) {
            $model = $models->first();

            if (!is_object($model)) {
                return;
            }

            if (!$this->isCascadable($model)) {
                return;
            }

            if (!in_array($model->getConnectionName(), $this->dbsToTransact)) {
                $this->dbsToTransact[] = $model->getConnectionName();
                DB::connection($model->getConnectionName())->beginTransaction();
            }

            $this->relations($model, $models->pluck($model->getKeyName()));
        }
    }
611311
public function dump($model = null)
    {
        if ($model) {
            $all = $this->all($model);
            Functions::dumpGrid($all, $model);
        } else {
            $this->dumpSchema();
        }
    }