本文整理汇总了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));
}
示例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);
}
}
}
示例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);
}
示例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;
}
示例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();
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
}
}
}
}
}
示例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);
});
}
示例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
}
示例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);
}
}
}
}