本文整理汇总了PHP中Illuminate\Database\Query\Builder类的典型用法代码示例。如果您正苦于以下问题:PHP Builder类的具体用法?PHP Builder怎么用?PHP Builder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Builder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: applyFilterConstraint
/**
* @param QueryBuilder $builder
* @param $data
*
* @return void
*/
public function applyFilterConstraint(QueryBuilder $builder, $data)
{
if (empty($data)) {
return;
}
$builder->whereIn($this->relation->getForeignKey(), explode(',', $data));
}
示例2: selectWhereIn
private function selectWhereIn($keys, Builder $query)
{
$results = [];
foreach (array_chunk($keys, 500) as $chunk) {
$results = array_merge($results, $this->connection->table($this->connection->raw("({$query->toSql()}) as query"))->whereIn("__key", $chunk)->get());
}
return collect($results)->keyBy("__key")->toArray();
}
示例3: processInsertGetId
/**
* Process an "insert get ID" query.
*
* @param \Illuminate\Database\Query\Builder $query
* @param string $sql
* @param array $values
* @param string $sequence
* @return int
*/
public function processInsertGetId(Builder $query, $sql, $values, $sequence = null)
{
$results = $query->getConnection()->selectFromWriteConnection($sql, $values);
$sequence = $sequence ?: 'id';
$result = (array) $results[0];
$id = $result[$sequence];
return is_numeric($id) ? (int) $id : $id;
}
示例4: processInsertGetId
/**
* Process an "insert get ID" query.
*
* @param \Illuminate\Database\Query\Builder $query
* @param string $sql
* @param array $values
* @param string $sequence
* @return int
*/
public function processInsertGetId(Builder $query, $sql, $values, $sequence = null)
{
$results = $query->getConnection()->select($sql, $values);
$sequence = $sequence ?: 'id';
$result = (array) $results[0];
return (int) $result[$sequence];
}
示例5: scopeCategory
/**
* Eloquent Scope for tag categories.
*
* @param \Illuminate\Database\Query\Builder $query
* @param string $category
*
* @return \Illuminate\Database\Query\Builder
*/
public function scopeCategory($query, $category)
{
if (!is_null($category)) {
return $query->where('category', '=', $category);
}
return $query;
}
示例6: scopeFindByRequest
/**
* Find by conditions in request
*
* @param Builder $query
* @param array|null $request
* @return \Illuminate\Database\Query\Builder
*/
public function scopeFindByRequest($query, $request = NULL)
{
if (is_null($request)) {
$request = Input::all();
}
$findable = isset($this->findable) ? $this->findable : [];
foreach ($request as $field => $value) {
if (!in_array($field, $findable)) {
continue;
}
if ($field == 'tag') {
if (isset($request['tag_search']) && $request['tag_search'] == 'any') {
$query->withAnyTag($value);
} else {
$query->withAllTags($value);
}
continue;
}
if (is_array($value)) {
$query->whereIn($field, $value);
} elseif (is_scalar($value)) {
$query->where($field, '=', $value);
}
}
}
示例7: scopeOfType
/**
* @param \Illuminate\Database\Query\Builder $query
* @param string $type
*
* @return \Illuminate\Database\Query\Builder
* @throws \Exception
*/
public function scopeOfType($query, $type = 'image')
{
if (!in_array($type, ['plain', 'image', 'audio', 'video', 'application'])) {
throw new \Exception();
}
return $query->where('mime', 'like', $type . '/%');
}
示例8: execute
public function execute(Builder $query)
{
$isWhere = false;
$count = 0;
foreach ($this->getValuesIterator() as $where) {
$operator = $where->getOperator();
if (array_key_exists($operator, WhereValidator::$especial_operator)) {
$method = $where->getOperatorValue();
switch ($method) {
case WhereValidator::$especial_operator['isNull']:
case WhereValidator::$especial_operator['isNotNull']:
$query->{$method}($where->getName());
break;
case WhereValidator::$especial_operator['between']:
case WhereValidator::$especial_operator['in']:
$query->{$method}($where->getName(), $where->getValue());
break;
}
continue;
} else {
if ($where->getOperatorValue() == WhereValidator::$operator['like']) {
$value = '%' . $where->getValue() . '%';
} else {
$value = $where->getValue();
}
}
$query->where($where->getName(), $where->getOperatorValue(), $value);
}
return $query;
}
示例9: compileJoins
protected function compileJoins(LaravelBaseBuilder $query, $joins)
{
$sql = array();
$query->setBindings(array(), 'join');
foreach ($joins as $join) {
$table = $this->wrapTable($join->table);
// First we need to build all of the "on" clauses for the join. There may be many
// of these clauses so we will need to iterate through each one and build them
// separately, then we'll join them up into a single string when we're done.
$clauses = array();
foreach ($join->clauses as $where) {
if (isset($where['type'])) {
$method = "where{$where['type']}";
$clauses[] = $where['boolean'] . ' ' . $this->{$method}($query, $where);
} else {
$clauses[] = $this->compileJoinConstraint($where);
}
}
foreach ($join->bindings as $binding) {
$query->addBinding($binding, 'join');
}
// Once we have constructed the clauses, we'll need to take the boolean connector
// off of the first clause as it obviously will not be required on that clause
// because it leads the rest of the clauses, thus not requiring any boolean.
$clauses[0] = $this->removeLeadingBoolean($clauses[0]);
$clauses = implode(' ', $clauses);
$type = $join->type;
// Once we have everything ready to go, we will just concatenate all the parts to
// build the final join statement SQL for the query and we can then return the
// final clause back to the callers as a single, stringified join statement.
$sql[] = "{$type} join {$table} on ({$clauses})";
}
return implode(' ', $sql);
}
示例10: __construct
/**
* Create a new join clause instance.
*
* @param \Illuminate\Database\Query\Builder $parentQuery
* @param string $type
* @param string $table
* @return void
*/
public function __construct(Builder $parentQuery, $type, $table)
{
$this->type = $type;
$this->table = $table;
$this->parentQuery = $parentQuery;
parent::__construct($parentQuery->getConnection(), $parentQuery->getGrammar(), $parentQuery->getProcessor());
}
示例11: where
/**
* {@inheritdoc}
*/
public function where(Builder $query, $value, $operator = '=')
{
if ($value === self::NULL_VALUE) {
$value = null;
}
return $query->where($this->initQuery($query), $operator, $value);
}
示例12: applyAnd
/**
* Call apply() within an "and" block
* @param \Illuminate\Database\Query\Builder $query
* @return \Illuminate\Database\Query\Builder $query
*/
public function applyAnd(\Illuminate\Database\Query\Builder $query)
{
$query->where(function ($query) {
$this->apply($query);
});
return $query;
}
示例13: constrainByModel
/**
* Constrain a query to an ability for a specific model.
*
* @param \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder $query
* @param \Illuminate\Database\Eloquent\Model $model
* @param bool $strict
* @return void
*/
protected function constrainByModel($query, Model $model, $strict = false)
{
$query->where(function ($query) use($model, $strict) {
$query->where($this->table . '.entity_type', $model->getMorphClass());
$query->where($this->abilitySubqueryConstraint($model, $strict));
});
}
示例14: prepareStatement
/**
* Get prepared statement.
*
* @param Builder $query
* @param string $sql
* @return \PDOStatement|\Yajra\Pdo\Oci8
*/
private function prepareStatement(Builder $query, $sql)
{
/** @var \Yajra\Oci8\Oci8Connection $connection */
$connection = $query->getConnection();
$pdo = $connection->getPdo();
return $pdo->prepare($sql);
}
示例15: order
/**
* {@inheritdoc}
*/
public function order(Builder $builder, $direction)
{
if ($this->columnClause !== null) {
$builder->orderBy($this->columnClause, $direction);
}
return $this;
}