Create new Model

@param Model $model

@return Model

@throws \Exception
192761
public function create(Model $model)
    {
        $data['model'] = $this->createModelData($model);

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

        return $this->getModelFromResult($modelResult);
    }
789625
public function saveEntity(Model $model)
    {
        $cacheKey = $this->cacheKey($model->toArray());
        $this->cache->forget($cacheKey);
        return $model->save();
    }
559162
public function createModel($scenario = 'insert')
    {
        /* @var File $model */
        $model = new $this->modelClass($scenario);
        if (!$model instanceof File) {
            throw new CException(sprintf('Model class "%s" must extend "File".', $this->modelClass));
        }
        return $model;
    }
811805
public function create( $model, $config = [] ) {

		$avatar = isset( $config[ 'avatar' ] ) ? $config[ 'avatar' ] : null;

		$modelClass = static::$modelClass;

		// Save Files
		$this->fileService->saveFiles( $model, [ 'avatarId' => $avatar ] );

		// Default Private
		$model->visibility = $model->visibility ?? $modelClass::VISIBILITY_PRIVATE;

		// Default New
		$model->status = $model->status ?? $modelClass::STATUS_NEW;

		// Create Model
		return parent::create( $model, $config );
	}
703650
public function createSubject(string $model): AbstractSubject
    {
        if (!isset($this->subjects[$model])) {
            throw new Exception(sprintf('Subject for model %s is not specified.', $model));
        } elseif (!class_exists($this->subjects[$model])) {
            throw new Exception(sprintf('Subject class for model %s does not exist.', $model));
        }

        $subject = new $this->subjects[$model]();
        if (!$subject instanceof AbstractSubject) {
            throw new Exception(sprintf('Subject for model %s is not instance of %s.', $model, AbstractSubject::class));
        }

        return $subject;
    }
1338617
public static function createFromModel(Model $model)
    {
        $table = $model->getTable();

        $dc = new static($table);

        $dc->strTable = $model->getTable();
        $dc->activeRecord = $model;
        $dc->intId = $model->id;

        return $dc;
    }
1007541
public function create($model = null, array $options = [])
    {
        $options = optionsParser($options);

        //It's a form inline with the `inline` option or the `form-inline` class
        if ($options->exists('inline') || $options->contains('class', 'form-inline')) {
            return self::createInline($model, $options->toArray());
        }

        return parent::create($model, $options->toArray());
    }
1353165
public function create($model, $data)
	{
		$params = $this->buildParams(array(
			$model,
			'create',
			$data
		));

		$response = $this->getClient('object')->call('execute', $params);

		return $response;
	}
909338
protected function createModel()
    {
        $model = parent::createModel();

        $translated = $this->util->getTranslated();
        $model->set('calc_used_date',
                'formatFunction', $translated->formatDateNever,
                'tdClass', 'date');
        $model->set('gto_changed',
                'dateFormat', 'dd-MM-yyyy HH:mm:ss',
                'tdClass', 'date');

        return $model;
    }
134562
public function setModel($model)
    {
        // convert the model class into an instance
        if (!is_object($model)) {
            $this->modelClass = $model;
            $model = new $model($this->modelId);
        } else {
            $this->modelId = $model->ids();
            $this->modelClass = get_class($model);
        }

        $this->model = $model;

        return $this;
    }
291972
protected function createModel()
    {
        if (! $this->model instanceof LogModel) {
            $this->model = $this->loader->getModels()->createLogModel();
            $this->model->applyDetailSettings();
        }
        return $this->model;
    }
724716
public function save(Model $model)
    {
        $model->setAttribute($this->getPlainMorphType(), $this->morphClass);

        return parent::save($model);
    }
256793
private function getAction(Model $Model)
	{
		$isCreate = true;
		$id = null;

		if (isset($Model->data[$Model->alias][$Model->primaryKey]) && !empty($Model->data[$Model->alias][$Model->primaryKey])) {
			$id = $Model->data[$Model->alias][$Model->primaryKey];
		}
		elseif (!empty($Model->id)) {
			$id = $Model->id;
		}

		if (!empty($id)) {
			$isCreate = !$Model->exists($id);
		}

		return $isCreate ? 'create' : 'modify';
	}
119163
public function create( $model, $config = [] ) {

		$this->updateBase( $model );

		return parent::create( $model, $config );
	}
1118071
public function creating(Model $model)
    {
        if (request()->hasFile('name')) {
            // delete prev image
            $file = $this->fileUploader->handle(request()->file('name'));
            $model->name = $file['filename'];
            $model->fill(Arr::except($file, 'filename'));
        } else {
            if ($model->type !== 'f') {
                return false;
            }
        }
    }
817923
private function createInsertObj(Model $model)
    {
        $metadata = $model->getMetadata();
        $insert = [
            $this->getIdentifierKey()   => $this->convertId($model->getId()),
        ];
        if (true === $metadata->isChildEntity()) {
            $insert[$this->getPolymorphicKey()] = $metadata->type;
        }
        return $this->appendChangeSet($model, $insert, $this->getCreateChangeSetHandler());
    }
607038
public function setModel($model)
    {
        Argument::i()->test(1, 'string');
        
        if ($model != Index::MODEL
        && !is_subclass_of($model, Index::MODEL)) {
            Exception::i()
                ->setMessage(Exception::NOT_SUB_MODEL)
                ->addVariable($model)
                ->trigger();
        }
        
        $this->model = $model;
        return $this;
    }