當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。