@param Model $model

@return Model
347539
protected static function encryptAttributes(Model $model)
    {
        foreach (static::getEncryptedAttributes() as $attribute) {
            try {
                $model->$attribute = static::getEncrypter()->encrypt($model->$attribute);
            } catch (EncryptException $e) {
            }
        }

        return $model;
    }
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;
    }
666932
private function doCommitDelete(Model $model)
    {
        $this->dispatchLifecycleEvent(Events::preDelete, $model);

        $this->getPersisterFor($model->getType())->delete($model);
        $model->getState()->setDeleted();

        $this->dispatchLifecycleEvent(Events::postDelete, $model);
        return $model;
    }
289284
public function associate(Model $model)
    {
        $this->parent->setAttribute($this->foreignKey, $model->getAttribute($this->otherKey));

        return $this->parent->setRelation($this->relation, $model);
    }
1112349
public function getModel($model)
    {
        if ($model instanceof EloquentModel) {
            return $model;
        }

        if (is_string($model) && class_exists($model)) {
            return $this->getModel(new $model());
        }

        throw new InvalidArgumentException("$model is not a valid model");
    }
217029
protected function getReference(Model $model)
    {
        $reference = $this->getReferenceValue($model);

        return $this->wrapReference($reference);
    }
857291
public function create(Model $model)
    {
        $metadata = $model->getMetadata();
        $insert = $this->createInsertObj($model);
        $this->getQuery()->executeInsert($metadata, $insert);
        return $model;
    }
528341
public function setModel($model)
    {
        $model->setSerializeNull($this->isSerializeNull());
        $this->setJson($model->toJson());

        return $this;
    }
50188
public function createClonedModel($model)
    {
        $clone = clone $model;
        $clone->setId(null);

        $environment  = $this->getEnvironment();
        $properties   = $environment->getDataDefinition()->getPropertiesDefinition();
        $dataProvider = $environment->getDataProvider($clone->getProviderName());

        foreach (\array_keys($clone->getPropertiesAsArray()) as $propName) {
            // If the property is not known, remove it.
            if (!$properties->hasProperty($propName)) {
                continue;
            }

            $property = $properties->getProperty($propName);
            $this->handleClonedModelProperty($clone, $property, $dataProvider);
        }

        return $clone;
    }
568530
public function onSave(Model $model)
    {
        $data            = $this->queryAttributes($model);
        $fieldData       = FieldData::query()->firstOrCreate($data);
        $fieldData->data = input($this->getName());
        return $fieldData->save();
    }
1281815
public function delete($model)
    {
        $this->fire($this->event('destroying'), [$model]);
        $model->delete();
        $this->fire($this->event('destroyed'), [$model]);
        return $model;
    }
295706
public function save($model)
    {
        if (isset($model->{$this->key})) {
            return $this->update($model);
        }
        
        return $this->create($model);
    }
925049
public function save(Model $model)
    {
        $model->setAttribute($this->getMorphType(), $this->morphClass);

        return parent::save($model);
    }
1075199
public function toType($model)
    {
        list($instance, $class) = $this->instanceAndClass($model);

        if ($type = $this->getFromCache($class)) {
            return $type;
        }

        $config = $this->buildConfig($instance, $class);

        $objectType = $this->typeFactory->toType("object|class:$class");

        $objectType->provideKeysBy(function () use (&$config) {
            return $this->typeFactory->toType($config);
        });

        return $this->putIntoCacheAndReturn($objectType);
    }
1193229
public function setModel(Model $model)
    {
        $this->model = $model;
        $append = $this->getAppends();

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

        return $this;
    }
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);
    }
247548
public function delete(Model $model)
    {
        $deleted = $model->delete();

        if ($deleted) {
            app('cache')->flush();
        }

        return $deleted;
    }