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


PHP Builder::whereIn方法代码示例

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


在下文中一共展示了Builder::whereIn方法的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: 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

示例3: findMany

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

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

示例5: deleteLimit

 /**
  *
  * Delete numbers of notifications equals
  * to the number passing as 2 parameter of
  * the current user
  *
  * @param $user_id    int
  * @param $entity
  * @param $number     int
  * @param $order      string
  * @return int
  * @throws \Exception
  */
 public function deleteLimit($user_id, $entity, $number, $order)
 {
     $notifications_ids = $this->notification->wherePolymorphic($user_id, $entity)->orderBy('id', $order)->select('id')->limit($number)->lists('id');
     if (count($notifications_ids) == 0) {
         return false;
     }
     return $this->notification->whereIn('id', $notifications_ids)->delete();
 }
开发者ID:naimkhalifa,项目名称:Notifynder,代码行数:21,代码来源:NotificationRepository.php

示例6: whereKey

 /**
  * Add a where clause on the primary key to the query.
  *
  * @param  mixed  $id
  * @return $this
  */
 public function whereKey($id)
 {
     if (is_array($id)) {
         $this->query->whereIn($this->model->getQualifiedKeyName(), $id);
         return $this;
     }
     return $this->where($this->model->getQualifiedKeyName(), '=', $id);
 }
开发者ID:illuminate,项目名称:database,代码行数:14,代码来源:Builder.php

示例7: whereIn

 /**
  * Extend of the eloquent whereIn function without error when empty array is given
  */
 public function whereIn($column, $values, $boolean = 'and', $not = false)
 {
     if (empty($values)) {
         $this->whereRaw(0);
     } else {
         parent::whereIn($column, $values, $boolean, $not);
     }
     return $this;
 }
开发者ID:jhaut,项目名称:eloquent-enhanced,代码行数:12,代码来源:Builder.php

示例8: scopeLevel

 /**
  * Lấy resources theo $level
  *
  * @param \Illuminate\Database\Query\Builder $query
  * @param int $level
  *
  * @return \Illuminate\Database\Query\Builder
  */
 public function scopeLevel($query, $level)
 {
     // Điều kiện: resources đang ở level $level
     $query->where("{$this->table}.level", '=', $level);
     if (!user()->inAdminGroup()) {
         switch ($level) {
             case ResourceLevel::LEVEL_CANHAN:
                 // Điều kiện: resources do chính user() tạo
                 $query->where("{$this->table}.user_id", '=', user('id'));
                 break;
             case ResourceLevel::LEVEL_DONVI:
                 // Điều kiện: resources của các user khác cùng đơn vị do user() làm thủ trưởng
                 if (user()->isGroupManager() && ($ids = user()->group->users->lists('id', 'username')->forget(user('username'))->all())) {
                     $query->whereIn("{$this->table}.user_id", $ids);
                 } else {
                     $query->whereRaw('1=0');
                 }
                 break;
             case ResourceLevel::LEVEL_COQUAN:
                 // Điều kiện: resources thuộc các categories user()-group được phép quản lý
                 if (user()->isGroupManager() && ($ids = user()->group->categories->lists('id')->all())) {
                     $query->whereIn("{$this->table}.category_id", $ids);
                 } else {
                     $query->whereRaw('1=0');
                 }
                 break;
             case ResourceLevel::LEVEL_BGH:
                 // Điều kiện: là thủ trưởng bgh
                 if (!user()->inBgh()) {
                     $query->whereRaw('1=0');
                 }
                 break;
             default:
                 $query->whereRaw('1=0');
         }
     }
     return $query;
 }
开发者ID:minhbang,项目名称:laravel-access-control,代码行数:46,代码来源:HasLevel.php

示例9: whereIn

 /**
  * Add a "where in" clause to the query.
  * Split one WHERE IN clause into multiple clauses each
  * with up to 1000 expressions to avoid ORA-01795
  *
  * @param  string $column
  * @param  mixed $values
  * @param  string $boolean
  * @param  bool $not
  * @return \Illuminate\Database\Query\Builder|\Yajra\Oci8\Query\OracleBuilder
  */
 public function whereIn($column, $values, $boolean = 'and', $not = false)
 {
     $type = $not ? 'NotIn' : 'In';
     if (count($values) > 1000) {
         $chunks = array_chunk($values, 1000);
         return $this->where(function ($query) use($column, $chunks, $type) {
             $firstIteration = true;
             foreach ($chunks as $ch) {
                 $sqlClause = $firstIteration ? 'where' . $type : 'orWhere' . $type;
                 $query->{$sqlClause}($column, $ch);
                 $firstIteration = false;
             }
         }, null, null, $boolean);
     }
     return parent::whereIn($column, $values, $boolean, $not);
 }
开发者ID:yajra,项目名称:laravel-oci8,代码行数:27,代码来源:OracleBuilder.php

示例10: fetchSelectedItems

 public function fetchSelectedItems(QueryBuilder $builder)
 {
     $self = $this;
     $this->filters->items[] = -1;
     //faço a busca de acordo com a palavra pesquisada, caso tenha uma:
     if ($this->filters->searchString) {
         if (count($this->filters->columns) > 0) {
             $builder->where(function ($q) use($self, $builder) {
                 foreach ($this->filters->columns as $column) {
                     if (!$column->bSearchable) {
                         continue;
                     }
                     $builder->orWhereRaw($column->name . " LIKE '%" . $self->filters->searchString . "%'");
                 }
             });
         }
     }
     if ($this->filters->checkedAll == 1) {
         $builder->whereNotIn($this->filters->idField, $this->filters->items);
         return $builder;
     }
     $builder->whereIn($this->filters->idField, $this->filters->items);
     return $builder;
 }
开发者ID:girolando,项目名称:componente-animal,代码行数:24,代码来源:DataTableQuery.php

示例11: 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)
 {
     $group_results = DB::table('tmp_group_user_count')->select('group_id');
     $query->whereIn('test_user_groups.group_id', $group_results->all());
     return $query;
 }
开发者ID:simmatrix,项目名称:laravel-query-builder-templates,代码行数:11,代码来源:UserGroupHasUserCount.php

示例12: parseFilter

 /**
  * Parse the remaining filter params
  *
  * @param  array $filterParams
  * @return void
  */
 protected function parseFilter($filterParams)
 {
     $supportedPostfixes = ['st' => '<', 'gt' => '>', 'min' => '>=', 'max' => '<=', 'lk' => 'LIKE', 'not-lk' => 'NOT LIKE', 'in' => 'IN', 'not-in' => 'NOT IN', 'not' => '!='];
     $supportedPrefixesStr = implode('|', $supportedPostfixes);
     $supportedPostfixesStr = implode('|', array_keys($supportedPostfixes));
     foreach ($filterParams as $filterParamKey => $filterParamValue) {
         $keyMatches = [];
         //Matches every parameter with an optional prefix and/or postfix
         //e.g. not-title-lk, title-lk, not-title, title
         $keyRegex = '/^(?:(' . $supportedPrefixesStr . ')-)?(.*?)(?:-(' . $supportedPostfixesStr . ')|$)/';
         preg_match($keyRegex, $filterParamKey, $keyMatches);
         if (!isset($keyMatches[3])) {
             if (strtolower(trim($filterParamValue)) == 'null') {
                 $comparator = 'NULL';
             } else {
                 $comparator = '=';
             }
         } else {
             if (strtolower(trim($filterParamValue)) == 'null') {
                 $comparator = 'NOT NULL';
             } else {
                 $comparator = $supportedPostfixes[$keyMatches[3]];
             }
         }
         $column = $keyMatches[2];
         if ($comparator == 'IN') {
             $values = explode(',', $filterParamValue);
             $this->query->whereIn($column, $values);
         } else {
             if ($comparator == 'NOT IN') {
                 $values = explode(',', $filterParamValue);
                 $this->query->whereNotIn($column, $values);
             } else {
                 $values = explode('|', $filterParamValue);
                 if (count($values) > 1) {
                     $this->query->where(function ($query) use($column, $comparator, $values) {
                         foreach ($values as $value) {
                             if ($comparator == 'LIKE' || $comparator == 'NOT LIKE') {
                                 $value = preg_replace('/(^\\*|\\*$)/', '%', $value);
                             }
                             //Link the filters with AND of there is a "not" and with OR if there's none
                             if ($comparator == '!=' || $comparator == 'NOT LIKE') {
                                 $query->where($column, $comparator, $value);
                             } else {
                                 $query->orWhere($column, $comparator, $value);
                             }
                         }
                     });
                 } else {
                     $value = $values[0];
                     if ($comparator == 'LIKE' || $comparator == 'NOT LIKE') {
                         $value = preg_replace('/(^\\*|\\*$)/', '%', $value);
                     }
                     if ($comparator == 'NULL' || $comparator == 'NOT NULL') {
                         $this->query->whereNull($column, 'and', $comparator == 'NOT NULL');
                     } else {
                         $this->query->where($column, $comparator, $value);
                     }
                 }
             }
         }
     }
 }
开发者ID:marcelgwerder,项目名称:laravel-api-handler,代码行数:69,代码来源:Parser.php

示例13: scopeWhichRoles

 /**
  * Take user by roles.
  *
  * @param \Illuminate\Database\Query\Builder $query
  * @param string|array $roles
  *
  * @return \Illuminate\Database\Query\Builder
  */
 public function scopeWhichRoles($query, $roles)
 {
     return $query->whereHas('roles', function ($query) use($roles) {
         $roles = is_array($roles) ? $roles : [$roles];
         $query->whereIn('name', $roles);
     });
 }
开发者ID:torome,项目名称:defender,代码行数:15,代码来源:HasRoles.php

示例14: whereIn

 public function whereIn($column, $values, $boolean = 'and', $not = false)
 {
     $column = is_string($column) ? snake_case($column) : $column;
     return parent::whereIn($column, $values, $boolean, $not);
     // TODO: Change the autogenerated stub
 }
开发者ID:jgraffite,项目名称:snake2camel,代码行数:6,代码来源:QueryBuilder.php

示例15: addWhereQuery

 /**
  * Add where to query builder
  * @param \Illuminate\Database\Query\Builder $query
  * @param array $subentity = null only add wheres with this subeneity
  */
 protected function addWhereQuery($query, $subentity = null)
 {
     // Ex with both filter and where: select * from `dms` where (`key` like ? or `name` like ?) and `disabled` = ?
     if (isset($this->where)) {
         foreach ($this->where as $where) {
             #$table = $where['table'];
             $column = $where['column'];
             $operator = $where['operator'];
             $value = $where['value'];
             if ($operator == 'in') {
                 #$query->whereIn("$table.$column", $value);
                 $query->whereIn($column, $value);
             } elseif ($operator == 'null') {
                 if ($value) {
                     $query->whereNull($column);
                 } else {
                     $query->whereNotNull($column);
                 }
             } else {
                 #$query->where("$table.$column", $operator, $value);
                 $query->where($column, $operator, $value);
             }
         }
     }
 }
开发者ID:mreschke,项目名称:repository,代码行数:30,代码来源:DbStore.php


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