本文整理汇总了PHP中Illuminate\Database\Eloquent\Builder::whereNotIn方法的典型用法代码示例。如果您正苦于以下问题:PHP Builder::whereNotIn方法的具体用法?PHP Builder::whereNotIn怎么用?PHP Builder::whereNotIn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Database\Eloquent\Builder
的用法示例。
在下文中一共展示了Builder::whereNotIn方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setNotIn
/**
* NotIn
*
* @param $key
* @param $value
* @return $this
*/
private function setNotIn($key, $value)
{
if (is_array($value)) {
$this->query->whereNotIn($key, $value);
}
return $this;
}
示例2: __call
/**
* @param $method
* @param $parameters
* @return Collection
* @throws \Exception
*
* sets cache key if derived class method call
* derived classes methods (like 'featured') are to be used as 'getFeatured'
*/
public function __call($method, $parameters)
{
$realMethod = lcfirst(substr($method, 3));
if (!method_exists($this, $realMethod)) {
throw new \Exception("Method does not exist - " . $method);
}
if ($this->cache) {
$this->cacheKey = ($this->onlyVisible ? '-' : '+') . ($this->onlyAuthored ? '-' : '+') . $this->baseName . ".{$realMethod}[" . serialize($parameters) . "]" . "\\{" . serialize($this->filters) . "\\}" . "<" . implode(',', $this->excludes) . ">";
if ($this->limit) {
$this->cacheKey .= "|{$this->limit}|";
}
if ($this->paginate) {
$this->cacheKey .= 'p=' . (Paginator::resolveCurrentPage() ?: 1) . "&pp=" . $this->perPage;
}
if ($this->closure) {
$this->cacheKey .= "{{$this->keyFragment}}";
}
if ($cache = Cache::get($this->cacheKey)) {
$this->clearFilters();
if ($this->appendExcludes) {
$this->excludes = array_merge($this->excludes, $cache->lists($this->identifier)->all());
$this->appendExcludes = false;
}
return $cache === 'null' ? null : $cache;
}
}
$this->model = new $this->modelClass();
$table = $this->model->getTable();
$this->model = $this->model->newQuery();
$this->model->select("{$table}.*");
$this->model = $this->model->whereNotIn($table . '.' . $this->identifier, $this->excludes);
$this->prepare($this->model);
$this->filter($this->model, $this->filters);
if ($this->onlyVisible) {
$this->filterVisible($this->model);
}
if ($this->onlyAuthored) {
$this->filterAuthored($this->model);
}
if ($this->limit) {
$this->model->take($this->limit);
}
array_unshift($parameters, $this->model);
call_user_func_array(array($this, $realMethod), $parameters);
if ($this->closure) {
$closure = $this->closure;
$closure($this->model);
}
$result = $this->get();
if ($this->appendExcludes) {
$this->excludes = array_merge($this->excludes, $result->lists($this->identifier)->all());
$this->appendExcludes = false;
}
$this->clearFilters();
return $result;
}
示例3: save
/**
* Store settings in the database.
*/
public function save()
{
if ($this->unsaved) {
$all = $this->getData();
$data = array_dot($all);
foreach ($data as $key => $value) {
$this->options->updateOrCreate(compact('key'), compact('key', 'value'));
}
$this->options->whereNotIn('key', array_keys($data))->delete();
$this->unsaved = false;
}
}
示例4: wherePermission
/**
*
* @param \Illuminate\Database\Eloquent\Builder $builder
* @param AclPermission $permission
* @param string $field
* @return \Illuminate\Database\Eloquent\Builder
*/
public function wherePermission($builder, AclPermission $permission, $field = null)
{
if (!$field) {
$field = $this->getAclKey();
}
if ($permission->allowed && !$permission->values) {
return $builder;
}
if ($permission->allowed) {
$builder->whereIn($this->getTable() . '.' . $field, $permission->values);
return $builder;
}
if ($permission->values) {
$builder->whereNotIn($this->getTable() . '.' . $field, $permission->values);
return $builder;
}
throw new NoPermissionsException("No perrmision to " . $permission->resource);
// return $builder->whereRaw('1 = 0');
}
示例5: apply
/**
* Applies constraint to query.
*
* @param Builder $builder query builder
* @param string $field field name
*/
public function apply(Builder $builder, $field)
{
if (strpos($field, ':') !== false) {
list($model, $column) = explode(':', $field);
$model = explode('_', $model);
for ($i = 1; $i < count($model); $i++) {
$model[$i] = ucfirst($model[$i]);
}
$model = implode($model);
$field = str_replace(':', '.', $field);
$builder->whereHas($model, function ($query) use($field) {
$this->apply($query, $field);
});
} elseif ($this->operator == Constraint::OPERATOR_IN) {
$builder->whereIn($field, $this->value);
} elseif ($this->operator == Constraint::OPERATOR_NOT_IN) {
$builder->whereNotIn($field, $this->value);
} else {
$builder->where($field, $this->operator, $this->value);
}
}
示例6: find
/**
* @param User $actor
* @param Builder $query
*/
public function find(User $actor, Builder $query)
{
$query->whereNotIn('id', Tag::getIdsWhereCannot($actor, 'viewDiscussions'));
}
示例7: apply
/**
* @param Builder $where
* @param array $filters
* @param string $boolean
*/
protected static function apply(Builder $where, array $filters, $boolean)
{
foreach ($filters as $filterName => $valuePair) {
foreach ($valuePair as $key => $value) {
if (is_array($value) && count($value) > 0) {
$value = array_values($value);
if (count($value[0]) > 1) {
switch ($filterName) {
case BaseFilter::RANGES:
$where->whereBetween($key, [$value[0][0], $value[0][1]], $boolean);
break;
case BaseFilter::NOT_RANGES:
$where->whereNotBetween($key, [$value[0][0], $value[0][1]], $boolean);
break;
}
} else {
switch ($filterName) {
case BaseFilter::GROUP:
$where->whereIn($key, $value, $boolean);
break;
case BaseFilter::NOT_GROUP:
$where->whereNotIn($key, $value, $boolean);
break;
}
}
}
$value = (array) $value;
$value = array_shift($value);
switch ($filterName) {
case BaseFilter::GREATER_THAN_OR_EQUAL:
$where->where($key, '>=', $value, $boolean);
break;
case BaseFilter::GREATER_THAN:
$where->where($key, '>', $value, $boolean);
break;
case BaseFilter::LESS_THAN_OR_EQUAL:
$where->where($key, '<=', $value, $boolean);
break;
case BaseFilter::LESS_THAN:
$where->where($key, '<', $value, $boolean);
break;
case BaseFilter::CONTAINS:
$where->where($key, 'LIKE', '%' . $value . '%', $boolean);
break;
case BaseFilter::NOT_CONTAINS:
$where->where($key, 'NOT LIKE', '%' . $value . '%', $boolean);
break;
case BaseFilter::STARTS_WITH:
$where->where($key, 'LIKE', $value . '%', $boolean);
break;
case BaseFilter::ENDS_WITH:
$where->where($key, 'LIKE', '%' . $value, $boolean);
break;
case BaseFilter::EQUALS:
$where->where($key, '=', $value, $boolean);
break;
case BaseFilter::NOT_EQUAL:
$where->where($key, '!=', $value, $boolean);
break;
}
}
}
}
示例8: applyFilter
public function applyFilter(Filter $filter, $operator, array $params)
{
$column = $filter->getField();
$sqlLikeEscapes = ['%' => '\\%', '_' => '\\_'];
switch ($operator) {
// Zero-parameter operators
case 'empty':
$this->query->where(function ($query) use($column) {
$query->whereIn($column, ['', 0])->orWhereNull($column);
});
break;
case 'not-empty':
$this->query->where(function ($query) use($column) {
$query->whereNotIn($column, ['', 0])->whereNotNull($column);
});
break;
// Single-parameter operators
// Single-parameter operators
case 'eq':
$this->query->where($column, $params[0]);
break;
case 'ne':
$this->query->where(function ($query) use($column, $params) {
$query->where($column, '!=', $params[0])->orWhereNull($column);
});
break;
case 'lt':
$this->query->where($column, '<', $params[0]);
break;
case 'gt':
$this->query->where($column, '>', $params[0]);
break;
case 'lte':
$this->query->where($column, '<=', $params[0]);
break;
case 'gte':
$this->query->where($column, '>=', $params[0]);
break;
case 'starts-with':
$this->query->where($column, 'LIKE', strtr($params[0], $sqlLikeEscapes) . '%');
break;
case 'ends-with':
$this->query->where($column, 'LIKE', '%' . strtr($params[0], $sqlLikeEscapes));
break;
case 'contains':
$this->query->where($column, 'LIKE', '%' . strtr($params[0], $sqlLikeEscapes) . '%');
break;
case 'not-starts-with':
$this->query->where(function ($query) use($column, $params, $sqlLikeEscapes) {
$query->where($column, 'NOT LIKE', strtr($params[0], $sqlLikeEscapes) . '%')->orWhereNull($column);
});
break;
case 'not-ends-with':
$this->query->where(function ($query) use($column, $params, $sqlLikeEscapes) {
$query->where($column, 'NOT LIKE', '%' . strtr($params[0], $sqlLikeEscapes))->orWhereNull($column);
});
break;
case 'not-contains':
$this->query->where(function ($query) use($column, $params, $sqlLikeEscapes) {
$query->where($column, 'NOT LIKE', '%' . strtr($params[0], $sqlLikeEscapes) . '%')->orWhereNull($column);
});
break;
// Dual-parameter operators
// Dual-parameter operators
case 'between':
$this->query->whereBetween($column, $params);
break;
case 'not-between':
$this->query->where(function ($query) use($column, $params, $sqlLikeEscapes) {
$query->whereNotBetween($column, $params)->orWhereNull($column);
});
break;
// Unlimited-parameter operators
// Unlimited-parameter operators
case 'in':
$this->query->whereIn($column, $params);
break;
case 'not-in':
$this->query->whereNotIn($column, $params);
break;
}
return $this;
}
示例9: scopeNotCategoryGroup
/**
* Filter by Not Category Group
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param dynamic string $groupId
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeNotCategoryGroup(Builder $query, $groupId)
{
$groupIds = array_slice(func_get_args(), 1);
return $query->whereNotIn('categories.group_id', $groupIds);
}
示例10: queryFilters
/**
* Query filters.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @return \Illuminate\Database\Eloquent\Builder
*/
protected function queryFilters($query, $filters = [])
{
$filters = $filters ?: $this->filters;
foreach ($filters as $key => $filter) {
foreach ($filter as $operator => $values) {
$values = is_array($values) ? $values : [$values];
$operator = is_numeric($operator) ? '=' : $operator;
if ($operator == '=') {
$query->whereIn($key, $values);
} elseif ($operator == '!=') {
$query->whereNotIn($key, $values);
} elseif ($operator == 'null') {
$query->whereNull($key);
} elseif ($operator == 'not_null') {
$query->whereNotNull($key);
} else {
$query->where($key, $operator, head($values));
}
}
}
return $query;
}
示例11: scopeBut
/**
* @param Builder $builder
* @param Collection $pages
*/
public function scopeBut(Builder $builder, Collection $pages)
{
if ($pages->count() > 0) {
$builder->whereNotIn($this->getKeyName(), $pages->lists($this->getKeyName())->toArray());
}
}
示例12: applyOperation
/**
* Append where for a Quri operation
*
* @param Builder $builder
* @param Operation $operation
* @param $andOr
* @return Builder
* @throws ValidationException
*/
public function applyOperation($builder, Operation $operation, $andOr)
{
$fieldName = $this->getRealFieldName($operation->fieldName());
switch ($operation->operator()) {
case "eq":
$symbol = "=";
break;
case "neq":
$symbol = "!=";
break;
case "gt":
$symbol = ">";
break;
case "lt":
$symbol = "<";
break;
case "gte":
$symbol = ">=";
break;
case "lte":
$symbol = "<=";
break;
case "like":
$symbol = "like";
break;
case "between":
return $builder->whereBetween($fieldName, $operation->values(), $andOr);
case "in":
return $builder->whereIn($fieldName, $operation->values(), $andOr);
case "nin":
return $builder->whereNotIn($fieldName, $operation->values(), $andOr);
default:
throw new ValidationException("QURI string could not be parsed. Operator '{$operation->operator()}' not supported");
}
return $builder->where($fieldName, $symbol, $operation->firstValue(), $andOr);
}
示例13: scopeNotStatus
/**
* Filter by Entry Status
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param dynamic string $status
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeNotStatus(Builder $query, $status)
{
$statuses = is_array($status) ? $status : array_slice(func_get_args(), 1);
return $query->whereNotIn('channel_titles.status', $statuses);
}
示例14: _query
/**
* @param Builder $query
* @param string $field
* @param string $condition
*/
protected function _query(Builder $query, $field, $condition = 'and')
{
$query->whereNotIn($field, $this->getValue(), $condition);
}
示例15: filterBySearchTerm
/**
* Filters a relationship options query by a search term
*
* @param mixed $term
* @param \Illuminate\Database\Query\Builder $query
* @param \Frozennode\Administrator\Fields\Field $fieldObject
* @param array $selectedItems
* @param string $relatedKeyTable
*/
public function filterBySearchTerm($term, EloquentBuilder &$query, Field $fieldObject, array $selectedItems, $relatedKeyTable)
{
if ($term) {
$query->where(function ($query) use($term, $fieldObject) {
foreach ($fieldObject->getOption('search_fields') as $search) {
$query->orWhere($this->db->raw($search), 'LIKE', '%' . $term . '%');
}
});
//exclude the currently-selected items if there are any
if (count($selectedItems)) {
$query->whereNotIn($relatedKeyTable, $selectedItems);
}
//set up the limits
$query->take($fieldObject->getOption('num_options') + count($selectedItems));
}
}