当前位置: 首页>>代码示例>>PHP>>正文


PHP Builder::where方法代码示例

本文整理汇总了PHP中Illuminate\Database\Query\Builder::where方法的典型用法代码示例。如果您正苦于以下问题:PHP Builder::where方法的具体用法?PHP Builder::where怎么用?PHP Builder::where使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Illuminate\Database\Query\Builder的用法示例。


在下文中一共展示了Builder::where方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: find

 /**
  * Find a model by its primary key.
  *
  * @param  mixed  $id
  * @param  array  $columns
  * @return \Illuminate\Database\Eloquent\Model|static|null
  */
 public function find($id, $columns = array('*'))
 {
     if (is_array($id)) {
         return $this->findMany($id, $columns);
     }
     $this->query->where($this->model->getQualifiedKeyName(), '=', $id);
     return $this->first($columns);
 }
开发者ID:visualturk,项目名称:framework,代码行数:15,代码来源:Builder.php

示例8: it_load_events_for_aggregate

 /**
  * @test
  */
 public function it_load_events_for_aggregate()
 {
     $aggregateRootId = new BarId('BarId');
     $this->db->table('events')->willReturn($this->queryBuilder);
     $this->queryBuilder->where('aggregate_root_id', 'BarId')->willReturn($this->queryBuilder);
     $this->queryBuilder->chunk(1000, Argument::any())->willReturn(true);
     $this->eventStore->load($aggregateRootId);
 }
开发者ID:desmart,项目名称:laravel-event-sourcing,代码行数:11,代码来源:DbEventStoreTest.php

示例9: apply

 /**
  * Modify a Builder object. Changes here can be nested
  * @param  \Illuminate\Database\Query\Builder $query
  * @return  \Illuminate\Database\Query\Builder $query
  */
 public function apply(\Illuminate\Database\Query\Builder $query)
 {
     //modify $query here
     if ($this->minAge) {
         $query->where('test_users.dob', '<=', Carbon::now()->subYears($this->minAge)->toDateTimeString());
     }
     if ($this->maxAge) {
         $query->where('test_users.dob', '>=', Carbon::now()->subYears($this->maxAge)->toDateTimeString());
     }
     return $query;
 }
开发者ID:simmatrix,项目名称:laravel-query-builder-templates,代码行数:16,代码来源:UserAgeBetweenScope.php

示例10: addWhere

 /**
  * Add a "where" clause to the given query.
  *
  * @param  \Illuminate\Database\Query\Builder $query
  * @param  string $key
  * @param  string $extraValue
  * @return void
  */
 protected function addWhere($query, $key, $extraValue)
 {
     if ($extraValue === 'NULL') {
         $query->whereNull($key);
     } elseif ($extraValue === 'NOT_NULL') {
         $query->whereNotNull($key);
     } elseif (Str::startsWith($extraValue, '!')) {
         $query->where($key, '!=', mb_substr($extraValue, 1));
     } else {
         $query->where($key, $extraValue);
     }
 }
开发者ID:saj696,项目名称:pipe,代码行数:20,代码来源:DatabasePresenceVerifier.php

示例11: scopeForModel

 /**
  * 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
  * @return void
  */
 public function scopeForModel($query, Model $model)
 {
     $query->where(function ($query) use($model) {
         $query->where('entity_type', $model->getMorphClass());
         $query->where(function ($query) use($model) {
             $query->whereNull('entity_id');
             if ($model->exists) {
                 $query->orWhere('entity_id', $model->getKey());
             }
         });
     });
 }
开发者ID:Gummibeer,项目名称:bouncer,代码行数:19,代码来源:Ability.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: parseFullTextSearch

 /**
  * Parse the fulltext search parameter q
  *
  * @param  string $qParam
  * @param  array  $fullTextSearchColumns
  * @return void
  */
 protected function parseFullTextSearch($qParam, $fullTextSearchColumns)
 {
     if ($qParam == '') {
         //Add where that will never be true
         $this->query->whereRaw('0 = 1');
         return;
     }
     $fulltextType = Config::get('apihandler.fulltext');
     if ($fulltextType == 'native') {
         //Use pdo's quote method to be protected against sql-injections.
         //The usual placeholders unfortunately don't seem to work using AGAINST().
         $qParam = $this->query->getConnection()->getPdo()->quote($qParam);
         //Use native fulltext search
         $this->query->whereRaw('MATCH(' . implode(',', $fullTextSearchColumns) . ') AGAINST("' . $qParam . '" IN BOOLEAN MODE)');
         //Add the * to the selects because of the score column
         if (count($this->query->columns) == 0) {
             $this->query->addSelect('*');
         }
         //Add the score column
         $scoreColumn = Config::get('apihandler.fulltext_score_column');
         $this->query->addSelect($this->query->raw('MATCH(' . implode(',', $fullTextSearchColumns) . ') AGAINST("' . $qParam . '" IN BOOLEAN MODE) as `' . $scoreColumn . '`'));
     } else {
         $keywords = explode(' ', $qParam);
         //Use default php implementation
         $this->query->where(function ($query) use($fullTextSearchColumns, $keywords) {
             foreach ($fullTextSearchColumns as $column) {
                 foreach ($keywords as $keyword) {
                     $query->orWhere($column, 'LIKE', '%' . $keyword . '%');
                 }
             }
         });
     }
 }
开发者ID:marcelgwerder,项目名称:laravel-api-handler,代码行数:40,代码来源:Parser.php

示例14: filterSearch

 /**
  * Метод фильтрует данные по словам
  *
  * @param string|int $search
  * @param null       $value       word
  * @param string     $delimiter   equal sign - '=', 'like' ...
  * @param string     $beforeValue First sign before value
  * @param string     $afterValue  Last sign after value
  */
 protected function filterSearch($search, $value = null, $delimiter = '=', $beforeValue = '', $afterValue = '')
 {
     if ($search) {
         $value = trim($value);
         $search = trim($search);
         /** @var Model $model */
         $model = $this->_query->getModel();
         // поиск по словам
         if (is_string($search) || is_numeric($search)) {
             $this->_query->where(function ($query) use($model, $search, $value, $delimiter, $beforeValue, $afterValue) {
                 /** @var \Illuminate\Database\Eloquent\Builder $query */
                 $tableName = $model->getTable();
                 if ($value) {
                     if (Model::hasColumn($model, $search)) {
                         $query->orWhere($tableName . '.' . $search, $delimiter, $beforeValue . $value . $afterValue);
                     }
                 } else {
                     foreach (\Schema::getColumnListing($tableName) as $column) {
                         // из-за проблем поиска с кириллицей, костыль.
                         if (!preg_match("/[\\w]+/i", $search)) {
                             if (FilterEnum::hasFilterExecuteForCyrillicColumn($column)) {
                                 continue;
                             }
                         }
                         if (Model::hasColumn($model, $column)) {
                             $query->orWhere($tableName . '.' . $column, 'like', '%' . $search . '%');
                         }
                     }
                 }
             });
         }
     }
 }
开发者ID:assurrussa,项目名称:grid-view-vue,代码行数:42,代码来源:GridView.php

示例15: _wheres

 /**
  * like wheres function ,call by internal
  * @param array $conds
  * @return $this
  */
 protected function _wheres($conds)
 {
     foreach ($conds as $field => $opAndVal) {
         if (is_null($opAndVal)) {
             $opAndVal = [null];
         }
         $opAndVal = (array) $opAndVal;
         $op = strtolower(count($opAndVal) == 1 ? '=' : $opAndVal[0]);
         $val = last($opAndVal);
         $field = str_contains($field, '.') ? $field : $this->table . '.' . $field;
         switch ($op) {
             case 'in':
                 if (count($val) == 1) {
                     $this->operator->where($field, '=', $val[0]);
                 } else {
                     $this->operator->whereIn($field, $val);
                 }
                 break;
             case 'between':
                 $this->operator->whereBetween($field, $val);
                 break;
             case 'raw':
                 $this->operator->whereRaw($val);
                 break;
             default:
                 $this->operator->where($field, $op, $val);
         }
     }
     return $this;
 }
开发者ID:kyleing,项目名称:gtbool,代码行数:35,代码来源:DBOperator.php


注:本文中的Illuminate\Database\Query\Builder::where方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。