Insert the given attributes and set the ID on the model.

@param  \Illuminate\Database\Eloquent\Builder  $query
@param  array  $attributes
@return void
178496
protected function insertAndSetId(Builder $query, $attributes)
    {
        $id = $query->insertGetId($attributes, $keyName = $this->getKeyName());

        $this->setAttribute($keyName, $id);
    }
974621
protected function setQuery($query)
    {
        if (is_array($query)) {
            $query = http_build_query($query);
        }
        
        if (!$this->isValidQuery($query)) {
            throw new \InvalidArgumentException("Invalid query '$query'");
        }
        
        $this->query = (string)$query;
    }
137579
public function addVoterVote(VoterInterface $voter, array $attributes, int $vote)
    {
        $currentLogIndex = \count($this->currentLog) - 1;
        $this->currentLog[$currentLogIndex]['voterDetails'][] = [
            'voter' => $voter,
            'attributes' => $attributes,
            'vote' => $vote,
        ];
    }
627550
public function update(array $attributes = [], $id = null)
    {
        // This allows for update based on the primary key
        if ($id && $this->exists === false) {
            $this->setAttribute($this->getKeyName(), $id);
            $this->exists = true;
        }

        $this->syncOriginal();

        return $this->fill($attributes)->save();
    }
1291133
protected function applySearchClauses(Builder $query): void
    {
        if ($searched = $this->getAttribute('request')->search) {
            $this->getAttribute('searchableColumns')
                ->map(function (TableListColumn $column, int $key) use (&$query, $searched) {
                    $table = $column->getAttribute('customColumnTable');
                    $attribute = $column->getAttribute('customColumnTableRealAttribute')
                        ? $column->getAttribute('customColumnTableRealAttribute')
                        : $column->getAttribute('attribute');
                    if ($key > 0) {
                        $query->orWhere($table . '.' . $attribute, 'like', '%' . $searched . '%');
                    } else {
                        $query->where($table . '.' . $attribute, 'like', '%' . $searched . '%');
                    }
                });
        }
    }
594783
public function searchable(array $attributes, string $key = 'q'): void
    {
        $model = $this->resolveQueryBuilderFromModel($this->model);
        $request = $this->app->make('request');
        $value = $request->input($key);

        $request->merge(["{$key}" => \rawurlencode($value)]);

        $this->set('search', [
            'attributes' => $attributes,
            'key' => $key,
            'value' => $value,
        ]);

        $this->model = $this->setupWildcardQueryFilter($model, $value, $attributes);
    }
333611
protected function _insert($query, $params)
    {
        $db = $this->db;
        $sth = $db->prepare($query);

        foreach ($params as $key => $val) {
            if (is_int($val)) {
                $sth->bindValue("$key", $val, $db::PARAM_INT);
            } else {
                $sth->bindValue("$key", $val);
            }
        }

        $response = $sth->execute();

        if ($response) {

            $class = $this->_rowClass;
            $row = new $class($this, $db->lastInsertId());

            return $row;
        }
        return false;
    }
253096
public function fill(array $attributes)
    {
        foreach ($attributes as $key => $value) {
            if (array_search($key, $this->fillable) !== false) {
                $this->{$key} = $value;
            }
        }
    }
962287
public function updateSql(array $attributes)
    {
        $attrs = [];
        foreach ($attributes as $key => $value) {
            $attrs[$this->getModel()->convertToPrimaryKeyName($key)] = $value;
        }

        $sql = $this
            ->getQueryBuilder()
            ->update()
            ->table($this->getModel()->tableName())
            ->values($attrs)
            ->toSQL();

        return $sql;
    }
336285
public static function insertIgnore(array $attributes = [])
    {
        $model = new static();
        $driver = $model->GetConnection()->GetDriverName();
        switch ($driver) {
            case 'sqlite':
                return static::executeQuery('insert or ignore', $attributes);
                break;
            default:
                return static::executeQuery('insert ignore', $attributes);
                break;
        }
    }
547875
public function addAttributes(array $attributes)
    {
        foreach ($attributes as $key => $value) {
            $this->addAttribute($key, $value);
        }
    }
882208
private function applyAttributes($attributes)
    {
        if (array_key_exists('count', $attributes) && $attributes['count'] > 0) {
            $keys = array_keys($attributes);

            foreach ($keys as $key) {
                if (is_array($attributes[$key]) && array_key_exists(0, $attributes[$key])) {
                    // If the entry has multiple attributes, we'll make sure we loop through each one
                    if (array_key_exists('count', $attributes[$key]) && $attributes[$key]['count'] > 1) {
                        $data = [];

                        for ($i = 0; $i <= $attributes[$key]['count']; $i++) {
                            $data[] = $attributes[$key][$i];
                        }

                        $this->setAttribute($key, array_filter($data));
                    } else {
                        // Looks like only one attribute exists, let's set it
                        $this->setAttribute($key, $attributes[$key][0]);
                    }
                }
            }

            $this->applyExtraAttributes();
        }
    }
1362721
public function rawQuery($sql, array $attributes = [], $connection = null)
    {
        if (empty($this->statements[$sql]))
        {
            $this->statements[$sql] = $this->connection($connection)->prepare($sql);
        }

        $this->statements[$sql]->execute($attributes);

        return $this->statements[$sql];
    }
369883
private function buildQuery($table, $attributes = [])
    {
        if (class_exists($table)) {
            $query = $this->getQueryBuilderFromModel($table);
        } else {
            $query = $this->getQueryBuilderFromTable($table);
        }

        foreach ($attributes as $key => $value) {
            if (\is_array($value)) {
                call_user_func_array(array($query, "where"), $value);
            } elseif (is_null($value)) {
                $query->whereNull($key);
            } else {
                $query->where($key, $value);
            }
        }
        return $query;
    }
635752
protected function performInsert(QueryBuilder $query)
    {
        // Disparar evento de documento sendo criado
        if ($this->fireModelEvent('creating') === false) {
            return false;
        }

        // Verificar para atualizar os timestamps
        if ($this->usesTimestamps()) {
            $this->updateTimestamps();
        }

        // Inserir documento e capturar ID
        $id = $query->insertGetId($this->attributes);
        $this->setAttribute('_id', $id);

        // Marcar como model já carregou o documento
        $this->exists = true;

        // Disparar evento de documento criado
        $this->fireModelEvent('created', false);

        return true;
    }
578153
public function setAttributes(array $attributes): void
    {
        $this->checkAttributeAssignable(array_keys($attributes));

        $this->setRawAttributes($attributes);
    }
781880
public function addToQuery(&$query)
    {
        parent::addToQuery($query);

        foreach ($this->compositeDatabaseFields() as $field => $spec) {
            $table = $this->getTable();
            $key = $this->getName() . $field;
            if ($table) {
                $query->selectField("\"{$table}\".\"{$key}\"");
            } else {
                $query->selectField("\"{$key}\"");
            }
        }
    }