本文整理汇总了PHP中Illuminate\Database\Eloquent\Builder::whereIn方法的典型用法代码示例。如果您正苦于以下问题:PHP Builder::whereIn方法的具体用法?PHP Builder::whereIn怎么用?PHP Builder::whereIn使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Database\Eloquent\Builder
的用法示例。
在下文中一共展示了Builder::whereIn方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: scopeWithTag
public static function scopeWithTag(Builder $query, $tags, $type = 'slug')
{
$tags = (new static())->prepareTags($tags);
return $query->whereHas('tags', function ($query) use($type, $tags) {
$query->whereIn($type, $tags);
});
}
示例2: whereIn
/**
* Add a whereIn to the query
*
* @param string $field
* @param array $values
* @param bool $order
*
* @return $this
*/
public function whereIn($field, $values, $order = false)
{
$this->builder = $this->builder->whereIn($field, $values);
if ($order) {
$this->builder = $this->builder->orderByRaw(DB::raw("FIELD(" . $field . ", " . implode(',', $values) . ")"));
}
return $this;
}
示例3: scopeInLog
public function scopeInLog(Builder $query, ...$logNames) : Builder
{
if (is_array($logNames[0])) {
$logNames = $logNames[0];
}
return $query->whereIn('log_name', $logNames);
}
示例4: setIn
/**
* In
*
* @param $key
* @param $value
* @return $this
*/
private function setIn($key, $value)
{
if (is_array($value)) {
$this->query->whereIn($key, $value);
}
return $this;
}
示例5: onQuerying
/**
* Fired just before querying
* for table entries.
*
* @param Builder $query
*/
public function onQuerying(Builder $query)
{
$uploaded = $this->getUploaded();
$query->whereIn('id', $uploaded ?: [0]);
$query->orderBy('updated_at', 'ASC');
$query->orderBy('created_at', 'ASC');
}
示例6: apply
/**
* Apply the scope to a given Eloquent query builder.
*
* @param \Illuminate\Database\Eloquent\Builder $builder
* @return void
*/
public function apply(Builder $builder, Model $model)
{
$subclassTypes = array_keys($model->getSingleTableTypeMap());
if (!empty($subclassTypes)) {
$builder->whereIn($model->getQualifiedSingleTableTypeColumn(), $subclassTypes);
}
}
示例7: constrainWhereIsAll
/**
* Constrain the given users query by all provided roles.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param string $role
* @return \Illuminate\Database\Eloquent\Builder
*/
public function constrainWhereIsAll($query, $role)
{
$roles = array_slice(func_get_args(), 1);
return $query->whereHas('roles', function ($query) use($roles) {
$query->whereIn('name', $roles);
}, '=', count($roles));
}
示例8: 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)
{
if (isset($model->type_field) && isset($model->type)) {
if (!is_array($model->type)) {
$builder->where($model->type_field, $model->type);
} else {
$builder->whereIn($model->type_field, $model->type);
}
} elseif (isset($model->type)) {
if (!is_array($model->type)) {
$builder->where('type', $model->type);
} else {
$builder->whereIn('type', $model->type);
}
}
}
示例9: 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();
}
示例10: build
public function build(Builder $query)
{
if (is_array($this->title)) {
return $query->whereIn('title', $this->title);
} else {
return $query->where('title', '=', $this->title);
}
}
示例11: findAllBy
public function findAllBy($attribute, $value, $columns = ['*'])
{
$this->newQuery();
// Perform where in
if (is_array($value)) {
return $this->query->whereIn($attribute, $value)->get($columns);
}
return $this->query->where($attribute, '=', $value)->get($columns);
}
示例12: applySimpleFilter
/**
* Apply simple filter
*
* @param Filter $filter
*/
protected function applySimpleFilter(Filter $filter)
{
$value = (array) $filter->getValue();
if (count($value) > 1) {
$this->query->whereIn($filter->getField(), $value);
} else {
$this->query->where($filter->getField(), $filter->getOperator(), $value[0]);
}
}
示例13: build
public function build(Builder $query)
{
$query->join('assets_tags', 'assets_tags.asset_id', '=', 'assets.id');
if (is_array($this->tags)) {
$query->whereIn('assets_tags.tag', $this->tags)->groupBy('tag')->having(DB::raw('count(distinct tag)'), '=', count($this->tags));
} else {
$query->where('assets_tags.tag', '=', $this->tags);
}
return $query;
}
示例14: 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->whereIn($model->getStatusColumn(), [Status::APPROVED, Status::PENDING]);
}
$this->extend($builder);
}
示例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);
}