當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Query\Builder類代碼示例

本文整理匯總了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));
 }
開發者ID:guratr,項目名稱:cruddy,代碼行數:13,代碼來源:BelongsTo.php

示例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();
 }
開發者ID:ifgroup,項目名稱:merger,代碼行數:8,代碼來源:Merger.php

示例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;
 }
開發者ID:ngitimfoyo,項目名稱:Nyari-AppPHP,代碼行數:17,代碼來源:PostgresProcessor.php

示例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];
 }
開發者ID:Thomvh,項目名稱:turbine,代碼行數:16,代碼來源:PostgresProcessor.php

示例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;
 }
開發者ID:displore,項目名稱:tags,代碼行數:15,代碼來源:Tag.php

示例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);
         }
     }
 }
開發者ID:xEdelweiss,項目名稱:my-perfect-back-end,代碼行數:32,代碼來源:FindByRequestTrait.php

示例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 . '/%');
 }
開發者ID:audithsoftworks,項目名稱:basis,代碼行數:14,代碼來源:File.php

示例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;
 }
開發者ID:brenodouglas,項目名稱:QueryApi,代碼行數:30,代碼來源:WhereCollection.php

示例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);
 }
開發者ID:fembri,項目名稱:eloficient,代碼行數:34,代碼來源:MysqlGrammar.php

示例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());
 }
開發者ID:delatbabel,項目名稱:framework,代碼行數:15,代碼來源:JoinClause.php

示例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);
 }
開發者ID:lazychaser,項目名稱:shopping,代碼行數:10,代碼來源:AbstractProperty.php

示例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;
 }
開發者ID:simmatrix,項目名稱:laravel-query-builder-templates,代碼行數:12,代碼來源:AbstractScope.php

示例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));
     });
 }
開發者ID:JosephSilber,項目名稱:bouncer,代碼行數:15,代碼來源:AbilitiesForModel.php

示例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);
 }
開發者ID:yajra,項目名稱:laravel-oci8,代碼行數:14,代碼來源:OracleProcessor.php

示例15: order

 /**
  * {@inheritdoc}
  */
 public function order(Builder $builder, $direction)
 {
     if ($this->columnClause !== null) {
         $builder->orderBy($this->columnClause, $direction);
     }
     return $this;
 }
開發者ID:guratr,項目名稱:cruddy,代碼行數:10,代碼來源:Computed.php


注:本文中的Illuminate\Database\Query\Builder類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。