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


PHP Builder::where方法代码示例

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


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

示例1: scopeSearch

 /**
  * Apply filters in your QueryBuilder based in $fields
  *
  * @param \Illuminate\Database\Eloquent\Builder $queryBuilder
  * @param array $fields
  *
  */
 public function scopeSearch(Builder $queryBuilder, $fields = [])
 {
     if (isset($this->searchable)) {
         foreach ($fields as $field => $value) {
             if (array_key_exists($field, $this->searchable)) {
                 switch ($this->searchable[$field]) {
                     // compare equals values
                     case 'MATCH':
                         $queryBuilder->where($field, $value);
                         break;
                         // compare like values
                     // compare like values
                     case 'LIKE':
                         array_map(function ($value) use($queryBuilder, $field) {
                             $queryBuilder->where($field, "LIKE", "%" . $value . "%");
                         }, explode(" ", $value));
                         break;
                         // compare between values
                     // compare between values
                     case 'BETWEEN':
                         if (is_array($value) && count($value) == 2) {
                             if (isset($value[0]) && !empty($value[0])) {
                                 $queryBuilder->where($field, ">=", $value[0]);
                             }
                             if (isset($value[1]) && !empty($value[1])) {
                                 $queryBuilder->where($field, "<=", $value[1]);
                             }
                         }
                 }
             }
         }
     }
     return $queryBuilder;
 }
开发者ID:dlimars,项目名称:laravel-searchable,代码行数:41,代码来源:Searchable.php

示例2: scopeEnabled

 /**
  * @param \Illuminate\Database\Eloquent\Builder $query
  * @param int                                   $id
  *
  * @return \Illuminate\Database\Eloquent\Builder
  */
 public function scopeEnabled($query, $id = null)
 {
     if ($id) {
         $query->where('id', '=', $id);
     }
     return $query->where('disabled', '=', false);
 }
开发者ID:vampirekiss,项目名称:lumen-restful-starter-kit,代码行数:13,代码来源:Client.php

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

示例4: processWhere

 /**
  * @param Builder $query
  * @param $wheres
  */
 private function processWhere(Builder $query, $wheres)
 {
     $self = $this;
     foreach ($wheres as $where) {
         /** @var WhereParameter $where */
         $query->where(function (Builder $query) use($self, $where) {
             if ($comparison = $where->getComparison()) {
                 $query->where($comparison->getSubject(), $comparison->getOperator(), $comparison->getValue());
             }
             foreach ($where->getChildren() as $child) {
                 if ($child instanceof AndConjunction) {
                     $query->where(function (Builder $query) use($self, $child) {
                         $this->processWhere($query, [$child->getSubject()]);
                     });
                 } elseif ($child instanceof OrConjunction) {
                     $query->orWhere(function (Builder $query) use($self, $child) {
                         $this->processWhere($query, [$child->getSubject()]);
                     });
                 } else {
                     throw new \InvalidArgumentException("Got an unknown conjunction");
                 }
             }
         });
     }
 }
开发者ID:catlabinteractive,项目名称:charon,代码行数:29,代码来源:ResourceController.php

示例5: like

 /**
  * Helper for "LIKE" filter
  *
  * @param  String $column
  * @param  String $value
  * @return Builder
  */
 protected function like($column, $value)
 {
     if ($this->builder->getQuery()->getConnection()->getDriverName() == 'pgsql') {
         return $this->builder->where($column, 'ILIKE', '%' . $value . '%');
     }
     return $this->builder->where($column, 'LIKE', '%' . $value . '%');
 }
开发者ID:kblais,项目名称:query-filter,代码行数:14,代码来源:QueryFilter.php

示例6: build

 public function build(Builder $query)
 {
     if (is_array($this->pageId)) {
         return $query->where('pages.id', 'not in', $this->pageId);
     } else {
         return $query->where('pages.id', '!=', $this->pageId);
     }
 }
开发者ID:boomcms,项目名称:boom-core,代码行数:8,代码来源:IgnorePages.php

示例7: searchWithTags

 private function searchWithTags(Query $query, stdClass $argument)
 {
     return $query->where(function (Query $query) use($argument) {
         $query->where('unit.name', $argument->operator, $argument->value)->orWhereHas('tags', function (Query $query) use($argument) {
             $query->where('name', $argument->operator, $argument->value);
         });
     });
 }
开发者ID:xandros15,项目名称:aigisu,代码行数:8,代码来源:UnitSearch.php

示例8: getByCredentials

 /**
  * @inheritdoc
  */
 public function getByCredentials(array $credentials)
 {
     foreach ($credentials as $key => $value) {
         if (strpos($key, 'password') === false) {
             $this->queryBuilder->where($key, $value);
         }
     }
     return $this->queryBuilder->first();
 }
开发者ID:yayatoure42,项目名称:service-exchange,代码行数:12,代码来源:UserStorage.php

示例9: scopeActive

 public function scopeActive(Builder $query)
 {
     $time = Date::floorToMinute();
     return $query->where('disable', '')->where(function (Builder $query) use($time) {
         return $query->where('start', '')->orWhere('start', '<=', $time);
     })->where(function (Builder $query) use($time) {
         return $query->where('stop', '')->orWhere('stop', '>', $time + 60);
     });
 }
开发者ID:fuzzyma,项目名称:contao-eloquent-bundle,代码行数:9,代码来源:ActiveScopeTrait.php

示例10: modifyQuery

 public function modifyQuery(Builder $query)
 {
     if ($this->get('user_id')) {
         $query->where('user_id', $this->get('user_id'));
     }
     if ($this->get('role_id')) {
         $query->where('role_id', $this->get('role_id'));
     }
     return $query;
 }
开发者ID:ohiocms,项目名称:core,代码行数:10,代码来源:PaginateRequest.php

示例11: scopeFindSimilarSlugs

 /**
  * Query scope for finding "similar" slugs, used to determine uniqueness.
  *
  * @param \Illuminate\Database\Eloquent\Builder $query
  * @param \Illuminate\Database\Eloquent\Model $model
  * @param string $attribute
  * @param array $config
  * @param string $slug
  * @return \Illuminate\Database\Eloquent\Builder
  */
 public function scopeFindSimilarSlugs(Builder $query, Model $model, $attribute, $config, $slug)
 {
     $separator = $config['separator'];
     foreach ($config['uniqueWhere'] as $param) {
         if ($this->{$param}) {
             $query->where($param, $this->{$param});
         }
     }
     return $query->where($attribute, '=', $slug)->orWhere($attribute, 'LIKE', $slug . $separator . '%');
 }
开发者ID:ribrit,项目名称:eloquent-sluggable,代码行数:20,代码来源:Sluggable.php

示例12: where

 /**
  * Add a where to the query
  * @param  string $field
  * @param  string $operator
  * @param  string $value
  * @return $this
  */
 public function where($field, $operator = null, $value = null)
 {
     // If there is only two arguments, the second one is the value
     if (func_num_args() == 2) {
         $value = $operator;
         $operator = '=';
     }
     $this->builder = $this->builder->where($field, $operator, $value);
     return $this;
 }
开发者ID:kodebyraaet,项目名称:pattern,代码行数:17,代码来源:BaseRepository.php

示例13: apply

 /**
  * Apply the scope to a given Eloquent query builder.
  *
  * @param  \Illuminate\Database\Eloquent\Builder $builder
  * @param  \Illuminate\Database\Eloquent\Model $model
  *
  * @return void
  */
 public function apply(Builder $builder, Model $model)
 {
     $strict = isset($model::$strictModeration) ? $model::$strictModeration : config('moderation.strict');
     if ($strict) {
         $builder->where($model->getQualifiedStatusColumn(), '=', Status::APPROVED);
     } else {
         $builder->where($model->getQualifiedStatusColumn(), '!=', Status::REJECTED);
     }
     $this->extend($builder);
 }
开发者ID:hootlex,项目名称:laravel-moderation,代码行数:18,代码来源:ModerationScope.php

示例14: putProductCategory

 /**
  * @param string  $sku
  * @param Request $request
  *
  * @throws \Illuminate\Database\Eloquent\ModelNotFoundException
  *
  * @return \Illuminate\Http\RedirectResponse
  */
 public function putProductCategory(string $sku, Request $request)
 {
     /** @var Product $product */
     $product = $this->product->where('sku', '=', $sku)->firstOrFail();
     $category = $this->category->findOrFail($request->get('category-id'));
     $product->category()->associate($category);
     $product->save();
     $this->webUi->successMessage("Set category for `{$product->sku}` to `{$category->name}`.");
     return $this->webUi->redirect('products.show', [$product->sku]);
 }
开发者ID:hughgrigg,项目名称:ching-shop,代码行数:18,代码来源:CategoryController.php

示例15: applyLoggedInScope

 /**
  * Apply logged in scope.
  *
  * @param \Illuminate\Database\Eloquent\Builder  $query
  * @param \Gitamin\Models\User  $user
  *
  * @return \Illuminate\Database\Eloquent\Builder
  */
 public function applyLoggedInScope(Builder $query, User $user)
 {
     $isPrivate = function ($query) use($user) {
         $query->where('visibility_level', '=', self::VISIBILITY_PRIVATE)->where("{$this->tableName}.creator_id", '=', $user->id);
     };
     $whereVisible = function ($query) use($isPrivate) {
         $query->whereIn('visibility_level', [self::VISIBILITY_PUBLIC, self::VISIBILITY_LOGGED_IN])->orWhere($isPrivate);
     };
     return $query->where($whereVisible);
 }
开发者ID:xiaobailc,项目名称:Gitamin,代码行数:18,代码来源:VisibilityScope.php


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