Determines how the field is saved to a model.

@param \Illuminate\Database\Eloquent\Model $model
@param \Illuminate\Http\Request            $request

@return $this
323769
public function saveToModel(Model $model, Request $request)
    {
        $parameters = $this->parseFieldParameters();
        $isMulti = isset($parameters['maxFileCount']) && $parameters['maxFileCount'] > 1 ? true : false;

        if (! $isMulti) {
            return parent::saveToModel($model, $request);
        }

        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);
    }
684407
public function store(Request $request)
    {
        try {
            $field = $this->fields->save($request);
        } catch (Exception $e) {
            return $this->handleException($e, trans('soda::errors.create', ['object' => trans('soda::terminology.field')]));
        }

        return redirect()->route('soda.fields.edit', $field->getKey())->with('success', trans('soda::messages.created', ['object' => trans('soda::terminology.field')]));
    }
876469
public function save($model)
    {
        if ($model instanceof Collection || is_array($model)) {
            throw new InvalidArgumentException('Parameter $model must be an instance of \Illuminate\Database\Eloquent\Model');
        }

        $this->validation()->validate('save', $model->getAttributes());

        $this->beforeSaveModel($model);

        return $model->save();
    }
724716
public function save(Model $model)
    {
        $model->setAttribute($this->getPlainMorphType(), $this->morphClass);

        return parent::save($model);
    }
922990
public function onSave($model)
    {
        $apiRoles          = ApiRoles::firstOrNew(['role_id' => $model->id]);
        $apiRoles->enabled = (int) Input::get('enabled');
        try {
            $apiRoles->save();
        } catch (Exception $ex) {
            Log::emergency($ex);
            throw new Exception('Unable to save role.');
        }
    }
1180042
public function saveAction(Request $request)
    {
        $json_nodes = $request->get('nodes');

        if ($json_nodes) {
            $this->em = $this->getDoctrine()->getManager();

            foreach ($json_nodes as $id => $obj) {

                $contentNode = $this->em->find(ContentNode::class, $id);

                if ($contentNode) {

                    $className = $obj['class'];
                    unset($obj['class']);

                    $metaData = $this->getClassMetaData($className);

                    foreach ($obj as $key => $value) {

                        $method = 'set' . ucfirst($key);

                        if (method_exists($contentNode, $method)) {

                            if (!empty($metaData->associationMappings[$key])) {

                                $fieldMetaData = $metaData->associationMappings[$key];
                                $repo = $this->em->getRepository($fieldMetaData['targetEntity']);


                                //check if its just a standard relation
                                if (
                                in_array(
                                    $fieldMetaData['type'],
                                    array(
                                        ClassMetadataInfo::ONE_TO_MANY,
                                        ClassMetadataInfo::MANY_TO_MANY
                                    )
                                )
                                )
                                    $value = $repo->findById($value);
                                else
                                    $value = $repo->findOneById($value);

                            }

                            $contentNode->$method($value);
                        }
                    }

                    $this->em->persist($contentNode);
                }
            }

            $this->em->flush();

            return new JsonResponse(array('status' => 'saved'));
        } else {
            return new JsonResponse(array('status' => 'failed', 'msg' => 'Nothing to update.'));
        }

    }
142672
protected function save($model)
    {
        $method = $this->methods['save'];

        if (!method_exists($model, $method) || !is_callable([$model, $method])) {
            throw new SaveMethodNotFoundException(get_class($model), $method);
        }

        return $model->$method();
    }
227939
public function saveAction(Request $request)
    {
        $id = $request->get('id');
        $data = $request->get('data');
        $data = json_decode($data, true);

        $metaSetManager = $this->get('phlexible_meta_set.meta_set_manager');
        $metaSet = $metaSetManager->find($id);

        $metaSet->setRevision($metaSet->getRevision() + 1);

        $fields = [];
        foreach ($metaSet->getFields() as $field) {
            $fields[$field->getId()] = $field;
        }

        foreach ($data as $item) {
            if (!empty($item['options'])) {
                $options = [];
                foreach (explode(',', $item['options']) as $key => $value) {
                    $options[$key] = trim($value);
                }
                $item['options'] = implode(',', $options);
            }

            if (isset($fields[$item['id']])) {
                $field = $fields[$item['id']];
                unset($fields[$item['id']]);
            } else {
                $field = $metaSetManager->createMetaSetField()
                    ->setId(UuidUtil::generate());
            }

            $field
                ->setName($item['key'])
                ->setMetaSet($metaSet)
                ->setType($item['type'])
                ->setRequired(!empty($item['required']) ? 1 : 0)
                ->setSynchronized(!empty($item['synchronized']) ? 1 : 0)
                ->setReadonly(!empty($item['readonly']) ? 1 : 0)
                ->setOptions(!empty($item['options']) ? $item['options'] : null);

            $metaSet->addField($field);
        }

        $metaSet
            ->setModifyUser($this->getUser()->getDisplayName())
            ->setModifiedAt(new \DateTime());

        foreach ($fields as $field) {
            $metaSet->removeField($field);
        }

        $metaSetManager->updateMetaSet($metaSet);

        return new ResultResponse(true, "Fields saved for set {$metaSet->getName()}.");
    }
1179860
public function setOptionsFromModel($model)
    {
        if (!$model) {
            return $this;
        }

        if ($model->is_sortable && in_array($this->getField(), $model->getSortable())) {
            // The model dictates that this column should be sortable
            $this->setSortable(true);
        }

        $this->model = $model;

        return $this;
    }
1201351
public function createModel($model)
    {
        $schema = new Schema();

        $tableDef = $schema->createTable($model->getMeta()->getDbTable());
        // this assumes fields set_from_name has been invoked
        $primaryKeyFields = [];
        $unique_fields = [];
        $indexes = [];
        /** @var $field Field */
        /** @var $field ForeignKey */
        foreach ($model->getMeta()->localFields as $fname => $field) {
            $colName = $field->getColumnName();
            $type = $field->dbType($this->connection);
            // if we don't have a type skip
            if (empty($type)) {
                continue;
            }
            if ($field->primaryKey) {
                $primaryKeyFields[] = $model->getMeta()->primaryKey->getColumnName();
            } elseif ($field->isUnique()) {
                $unique_fields[] = $colName;
            } elseif ($field->dbIndex) {
                $indexes[] = $colName;
            }
            $tableDef->addColumn($colName, $type, $this->getDoctrineColumnOptions($field));
            if ($field->isRelation && $field->relation && $field->dbConstraint) {
                $relField = $field->getRelatedField();
                $tableDef->addForeignKeyConstraint(
                    $relField->scopeModel->getMeta()->getDbTable(),
                    [$field->getColumnName()],
                    [$relField->getColumnName()]
                );
            }
        }
        // create the primary key
        $tableDef->setPrimaryKey($primaryKeyFields);
        // add index constraint
        if (!empty($indexes)) {
            $tableDef->addIndex($indexes);
        }
        // add unique constraint
        if (!empty($unique_fields)) {
            $tableDef->addUniqueIndex($unique_fields);
        }
        $this->createTable($tableDef);
        // many to many
        /** @var $relationField ManyToManyField */
        foreach ($model->getMeta()->localManyToMany as $name => $relationField) {
            if ($relationField->manyToMany && $relationField->relation->through->getMeta()->autoCreated) {
                $this->createModel($relationField->relation->through);
            }
        }
    }
825210
public function beforeSave(Model &$model)
    {

        if ($model->isNew()) {
            if (empty($model->parent)) {
                $this->insertModelAsLastRoot($model);
            } else {
                $this->insertModelAsLastChildOf($model, $model->parent);
            }
        } else {
            /** @var \T4\Orm\Model $class */
            $class = get_class($model);
            $oldParent = empty($model->__prt) ? null : $class::findByPk($model->__prt);
            if ($oldParent != $model->parent) {
                $model->refreshTreeColumns();
                if (empty($model->parent)) {
                    $this->insertModelAsLastRoot($model);
                } else {
                    /** @var \T4\Dbal\Connection $connection */
                    $connection = $class::getDbConnection();
                    $query = new Query();
                    $query
                        ->select('count(*)')
                        ->from($class::getTableName())
                        ->where('__id=:id AND __lft>:lft AND __rgt<:rgt')
                        ->params([':id' => $model->parent->getPk(), ':lft'=>$model->__lft, ':rgt'=>$model->__rgt]);

                    if ($connection->query($query)->fetchScalar() > 0) {
                        throw new Exception('Parent must not be in children!');
                    }

                    $this->insertModelAsLastChildOf($model, $model->parent);
                }
            }
        }

        return true;

    }
839526
public function save(Model $model) {
        if ($model->isPrimaryKey($this->foreignKey)) {
            $model->save();
            $this->parent->{$this->localKey} = $model->{$this->foreignKey};
            $this->parent->save();
            return $this;
        }
        $model->{$this->foreignKey} = $this->parent->{$this->localKey};
        $model->save();
        return $this;
    }
226775
public function setModel(Model $model)
    {
        parent::setModel($model);
        $this->setHtmlAttribute('data-value', $this->getModelValue());

        return $this;
    }
192761
public function create(Model $model)
    {
        $data['model'] = $this->createModelData($model);

        $modelResult = $this->getRequest()->request(
            'POST',
            $this->getRequestUrl('models'),
            $data
        );

        return $this->getModelFromResult($modelResult);
    }
848554
public function saved(Model $model)
    {
        $tags = $this->processTags(request('tags'));
        $this->syncTags($model, $tags);
    }
1345434
public function save(Model $model)
    {
        if ($this->fieldId) {
            $model->setAttribute($this->fieldKey, $this->fieldId);
        }

        return parent::save($model);
    }