Fill a model with input data.

@param \Illuminate\Database\Eloquent\Model $model
@param mixed                               $input
190234
public function fillModel(&$model, $input)
    {
        $model->{$this->getOption('field_name')} = $input === 'true' || $input === '1' || $input === true ? 1 : 0;
    }
812743
public function update(int $id, array $input)
    {
        return $this->model->find($id)->update($input);
    }
936434
public function delete($input)
    {
        $pk = $this->getPrimaryKey();

        if ($input instanceof $this->model) {
            $primary = $input->getPrimaryKey();
        } else {
            $primary = $input;
        }

        $query = $this->newDeleteQuery();
        $query->where("$pk = ?", $primary);
        $query->limit(1);

        $this->getDB()->execute($query);
    }
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);
    }
945173
public function update(Model $model) {

		return $this->_populate(
			$this->_request('put', $this->_getUrl('element', $model->getPrimaryKey()), [
				'json' => $model->getAttributes()
			]),
			false
		);
	}
556735
public function setModel(Model $model)
    {
        parent::setModel($model);

        if ($model->exists) {
            $this->setInstance($model);
            $this->loadRelationValues();
        }
    }
1273519
private function filterModel(Input $input)
    {
        $models = array_filter(
            $this->findAllModels(),
            function (CommandInterface $command) use ($input) {
                return preg_match(preg_quote($command->getCmd()), $input->text);
            }
        );

        if (empty($models)) {
            return null;
        }

        return $models[0];
    }
238518
public function fillModel(&$model, $input)
    {
        $model->{$this->getOption('foreign_key')} = $input !== 'false' ? $input : null;

        $model->__unset($this->getOption('field_name'));
    }
700689
public function setBelongsToData(Model $model) {
        $typeAhead = array();

        foreach ($model->belongsTo as $alias => $assoc) {
            $object = Admin::introspectModel($assoc['className']);
            $count = $this->getRecordCount($object);

            // Add to type ahead if too many records
            if (!$count || $count > $object->admin['associationLimit']) {
                $class = $assoc['className'];

                if (mb_strpos($class, '.') === false) {
                    $class = Configure::read('Admin.coreName') . '.' . $class;
                }

                // Get the foreign key from the child -> parent
                $foreignKey = null;

                foreach ($object->belongsTo as $childAssoc) {
                    if ($childAssoc['className'] === $model->name) {
                        $foreignKey = $childAssoc['foreignKey'];
                        break;
                    }
                }

                $typeAhead[$assoc['foreignKey']] = array(
                    'alias' => $alias,
                    'model' => $class,
                    'foreignKey' => $foreignKey
                );

            } else {
                $variable = Inflector::variable(Inflector::pluralize(preg_replace('/(?:_id)$/', '', $assoc['foreignKey'])));

                $this->Controller->set($variable, $this->getRecordList($object));
            }
        }

        $this->Controller->set('typeAhead', $typeAhead);
    }
981357
public function setInput($input)
    {
        $this->input       = preg_replace("/\r\n|\r/", "\n", $input);
        $this->lineno      = 1;
        $this->deferred    = array();
        $this->indentStack = array();
        $this->stash       = array();
    }
376121
public function setModel($model)
    {
        if (false !== $pos = strrpos($model, '\\')) {
            $this->model = substr($model, $pos + 1);
        } else {
            $this->model = $model;
        }
        $this->fullyQualifiedModel = ((0 === strpos($model, '\\')) ? '' : '\\') . $model;
    }
930208
protected function saving(Eloquent $model, $input = [], $type = 'create')
    {
        $beforeEvent = ($type === 'create' ? 'creating' : 'updating');
        $afterEvent  = ($type === 'create' ? 'created' : 'updated');


        $this->fireEvent($beforeEvent, [$model]);
        $this->fireEvent('saving', [$model]);
        $attributes = [
            'label'       => $input['label'],
            'description' => $input['description'],
            'placeholder' => array_get($input, 'placeholder'),
            'value'       => array_get($input, 'value'),
        ];

        if (!is_null($name = array_get($input, 'name'))) {
            array_set($attributes, 'name', $name);
        }
        if (!is_null($name = array_get($input, 'name'))) {
            array_set($attributes, 'name', $name);
        }
        if (isset($input['group'])) {
            $attributes['group_id'] = $input['group'];
        }
        if (isset($input['type'])) {
            $attributes['type_id'] = $input['type'];
        }
        array_set($attributes, 'force_display', (int) isset($input['force_display']));
        if (isset($input['additional_attributes'])) {
            $attributes['additional_attributes'] = $input['additional_attributes'];
        }
        $model->fill($attributes);
        DB::transaction(function () use ($model, $input) {
            if ($model->exists) {
                $model->validators()->delete();
            }
            $model->save();
            $this->saveFieldsets($model);
            $fieldId = $model->id;

            if (isset($input['validators'])) {

                foreach ($input['validators'] as $validatorId) {
                    $configuration = Foundation::make('antares.customfields.model.validator.config')->newInstance();
                    $attribs       = [
                        'field_id'     => $fieldId,
                        'validator_id' => $validatorId,
                        'value'        => isset($input['validator_custom'][$validatorId]) ? $input['validator_custom'][$validatorId] : null
                    ];
                    $configuration->fill($attribs);
                    $configuration->save();
                }
            }
            if (isset($input['option'])) {
                $optionFoundation = Foundation::make('antares.customfields.model.type.option');
                $keys             = [];
                foreach ($input['option'] as $index => $optionValue) {
                    if (strlen($optionValue) > 0) {
                        if ($model->exists) {
                            $option = $optionFoundation::firstOrNew([
                                        'label'    => $input['option_label'][$index],
                                        'value'    => $optionValue,
                                        'field_id' => $fieldId
                            ]);
                        } else {
                            $option = $optionFoundation->newInstance();
                        }
                        $attribs = [
                            'field_id' => $fieldId,
                            'label'    => $input['option_label'][$index],
                            'value'    => $optionValue
                        ];
                        $option->fill($attribs);
                        $option->save();
                        $keys[]  = $optionValue;
                    }
                }
                foreach ($model->options as $option) {
                    if (!in_array($option->value, $keys)) {
                        $option->delete();
                    }
                }
            }
        });

        $this->fireEvent($afterEvent, [$model]);
        $this->fireEvent('saved', [$model]);

        return true;
    }
302498
public function createModel(InputInterface $input, OutputInterface $output)
    {
        $model = $this->getApplication()->find('create:model');
        $model_arguments = array(
            'command'   => 'create:model',
            'module'    => $input->getArgument('module'),
            'table'     => $input->getArgument('table'),
            'column'    => $input->getArgument('column')
        );

        $input_model = new ArrayInput($model_arguments);
        $return_model= $model->run($input_model,$output);
        $output->writeln($return_model);
    }
137363
public function process($model, $input)
    {
        $column = $this->getColumn();

        // Handle a special case where the data in the database is 0000-00-00 00:00:00
        if ($input[$column] == '-0001-11-30 00:00:00' || $input[$column] == '0000-00-00 00:00:00')
        {
            $model->{$column} = Carbon::now();
        }
        elseif (isset($input[$column]))
        {
            $model->{$column} = $input[$column];
        }

        if (empty($input[$column])) $model->{$column} = null;

        return $model;
    }
664757
protected function prepareModel(Model $model)
    {
        if (is_callable($this->prepareModel)) {
            call_user_func($this->prepareModel, $model);
        } else {
            foreach ($model->attributes() as $attribute) {
                $value = Yii::$app->settings->get($this->getSection($model), $attribute);

                if (!is_null($value)) {
                    $model->{$attribute} = $value;
                }
            }
        }
    }
1018439
private function fillModel(AbstractModel $model, array $data)
    {
        if (!$data) {
            return $model;
        }

        $reflection = new \ReflectionClass($model);
        foreach($reflection->getProperties() as $property) {
            $property->setAccessible(true);
            $property->setValue($model, $data[$property->getName()]);
            $property->setAccessible(false);
        }

        return $model;
    }
1364801
public function fillModel(&$model, $input)
    {
        // $input is an array of all foreign key IDs
        //
        // $model is the model for which the above answers should be associated to
        $fieldName    = $this->getOption('field_name');
        $input        = $input ? explode(',', $input) : array();
        $relationship = $model->{$fieldName}();

        // get the plain foreign key so we can set it to null:
        $fkey = $relationship->getPlainForeignKey();

        $relatedObjectClass = get_class($relationship->getRelated());

        // first we "forget all the related models" (by setting their foreign key to null)
        foreach ($relationship->get() as $related) {
            $related->$fkey = null; // disassociate
            $related->save();
        }

        // now associate new ones: (setting the correct order as well)
        $i = 0;
        foreach ($input as $foreign_id) {
            $relatedObject = call_user_func($relatedObjectClass.'::find', $foreign_id);
            if ($sortField = $this->getOption('sort_field')) {
                $relatedObject->$sortField = $i++;
            }

            $relationship->save($relatedObject);
        }
    }