/** * Applies parameter filtering for a given query * * @param string $name * @param mixed $value * @param EloquentBuilder $query * @param FilterInterface $filter * @return EloquentBuilder */ public function apply($name, $value, $query, FilterInterface $filter) { $column = (!empty($this->table) ? $this->table . '.' : null) . (!empty($this->column) ? $this->column : $name); return $query->where(function ($query) use($column) { return $query->whereNull($column)->orWhere($column, ''); }); }
public function execute(Builder $query) { if ($this->group) { return $query->where('group', '=', $this->group); } else { return $query->whereNull('group'); } }
public function build(Builder $query) { if ($this->parentId) { return $query->where('parent_id', '=', $this->parentId); } else { return $query->whereNull('parent_id'); } }
/** * @param Builder $query * * @return Builder */ public function build(Builder $query) { if ($this->page === null) { return $query->whereNull('parent_id'); } list($col, $direction) = $this->page->getChildOrderingPolicy(); return $query->where('parent_id', '=', $this->page->getId())->orderBy($col, $direction); }
/** * @param User $actor * @param Builder $query */ public function find(User $actor, Builder $query) { if (!$actor->hasPermission('discussion.hide')) { $query->where(function ($query) use($actor) { $query->whereNull('discussions.hide_time')->where('comments_count', '>', 0)->orWhere('start_user_id', $actor->id); $this->events->fire(new ScopeHiddenDiscussionVisibility($query, $actor, 'discussion.hide')); }); } }
/** * Overriding newQuery() to the custom PostBuilder with some intereting methods * * @param bool $excludeDeleted * @return Corcel\PostBuilder */ public function newQuery($excludeDeleted = true) { $builder = new Builder($this->newBaseQueryBuilder()); $builder->setModel($this); $builder->leftJoin('wp_term_taxonomy', 'wp_terms.term_id', '=', 'wp_term_taxonomy.term_id')->where('wp_term_taxonomy.taxonomy', '=', 'category')->select('wp_terms.*'); if ($excludeDeleted and $this->softDelete) { $builder->whereNull($this->getQualifiedDeletedAtColumn()); } return $builder; }
/** * 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 * @return void */ public function scopeForModel($query, Model $model) { $query->where(function ($query) use($model) { $query->where('entity_type', $model->getMorphClass()); $query->where(function ($query) use($model) { $query->whereNull('entity_id'); if ($model->exists) { $query->orWhere('entity_id', $model->getKey()); } }); }); }
/** * @param Builder $builder * @param Collection $tags * @return Builder */ public function scopeTaggedWith(Builder $builder, Collection $tags) { /** @var MorphToMany $relation */ $relation = $this->tags(); $key = $this->getTable() . '.' . $this->getKeyName(); if ($tags->count()) { $builder->join($relation->getTable(), function ($join) use($relation, $key, $tags) { $join->on($relation->getForeignKey(), '=', $key); $join->where($relation->getMorphType(), '=', $relation->getMorphClass()); $join->whereIn($relation->getOtherKey(), $tags->keys()->toArray()); }); } else { $builder->whereNull($this->getTable()); } return $builder; }
/** * Aplicar. * * @param Builder $builder * @param Model $model */ public function apply(Builder $builder, Model $model) { // Verificar se deve filtrar o inquilino if (isset($model->multTenant) && $model->multTenant == true) { // Verificar se esta logado if (is_null(\Auth::id())) { return; } // Verificar qual o inquilino informado $inquilino_id = \Auth::user()->{Table::tenantField()}; if (is_null($inquilino_id)) { $builder->whereNull(Table::tenantField()); } else { $builder->where(Table::tenantField(), $inquilino_id); } } }
/** * Finds all non-scheduled incidents. * * @param \Illuminate\Database\Eloquent\Builder $query * * @return \Illuminate\Database\Eloquent\Builder */ public function scopeNotScheduled(Builder $query) { return $query->where('status', '>', 0)->orWhere(function ($query) { $query->where('status', 0)->where(function ($query) { $query->whereNull('scheduled_at')->orWhere('scheduled_at', '<=', Carbon::now()->toDateTimeString()); }); }); }
/** * Constrain a query to an permission for a specific model. * * @param \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder $query * @param \Illuminate\Database\Eloquent\Model|string $model * @param bool $strict * @return void */ public function scopeForModel($query, $model, $strict = false) { $model = is_string($model) ? new $model() : $model; $query->where(function ($query) use($model, $strict) { $query->where('entity_type', $model->getMorphClass()); $query->where(function ($query) use($model, $strict) { // If the model does not exist, we want to search for blanket permissions // that cover all instances of this model. If it does exist, we only // want to find blanket permissions if we're not using strict mode. if (!$model->exists || !$strict) { $query->whereNull('entity_id'); } if ($model->exists) { $query->orWhere('entity_id', $model->getKey()); } }); }); }
/** * Returns all the guest users. * * @param \Illuminate\Database\Eloquent\Builder $query * @return \Illuminate\Database\Eloquent\Builder */ public function scopeGuests(Builder $query) { return $query->whereNull('user_id'); }
private function generateNullConditionFromHasOneOrMany(HasOneOrMany $relation) { $this->query = $this->query->whereNull($relation->getForeignKey()); }
public function scopeParents(Builder $builder) { $builder->whereNull('parent_id'); }
/** * Add a whereNull to the query * * @param $field * @return mixed */ public function whereNull($field) { $this->builder = $this->builder->whereNull($field); return $this; }
/** * Get a new query builder for the model's table. * * @param bool $excludeDeleted * @return \Illuminate\Database\Eloquent\Builder|static */ public function newQuery($excludeDeleted = true) { $builder = new Builder($this->newBaseQueryBuilder()); // Once we have the query builders, we will set the model instances so the // builder can easily access any information it may need from the model // while it is constructing and executing various queries against it. $builder->setModel($this)->with($this->with); if ($excludeDeleted and $this->softDelete) { $builder->whereNull($this->getQualifiedDeletedAtColumn()); } return $builder; }
/** * Overwrite the whereNull method to add the table name in front of the column * * @param $column * @param string $boolean * @param bool|false $not * @return mixed */ public function whereNull($column, $boolean = 'and', $not = false) { return parent::whereNull($this->getModelTableColumn($column), $boolean, $not); }
/** * Modifies the query to only include files without clippables. * * @param Builder $query * @return Builder */ public function scopeUnattached(Builder $query) { return $query->whereNull('clippable_id')->whereNull('clippable_type'); }
/** * @param Builder $builder * @return Builder */ public function scopeExpired(Builder $builder) { $builder->whereNull('expired_at')->orWhere('expired_at', '<=', Carbon::now()); return $builder; }
public function scopeActive(Builder $query) { $query->whereNull('approved'); }
public function apply(Builder $builder, Model $model) { $builder->whereNull($model->getQualifiedArchivedAtColumn()); }
/** * Scopes to non-hooked repositories. * * @param \Illuminate\Database\Eloquent\Builder $builder * * @return \Illuminate\Database\Eloquent\Builder */ public function scopeNotHooked(Builder $builder) { return $builder->whereNull('hook_id'); }
/** * Constrain a query to simple abilities. * * @param \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder $query * @return void */ public function scopeSimpleAbility($query) { $query->whereNull("{$this->table}.entity_type"); }
/** * 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; }
/** * Query scope for active groups. */ public function scopeActive(Builder $query) { return $query->whereNull($this->getInactiveColumn()); }
/** * Scope for get node items of root * * @param Builder $query query builder * @return Builder */ public function scopeRoots(Builder $query) { return $query->whereNull($this->getParentIdName())->orderBy($this->getOrderKeyName(), 'asc'); }
/** * Finds all non-scheduled incidents. * * @param \Illuminate\Database\Eloquent\Builder $query * * @return \Illuminate\Database\Eloquent\Builder */ public function scopeNotScheduled($query) { return $query->where(function ($query) { return $query->whereNull('scheduled_at')->orWhere('scheduled_at', '<=', Carbon::now()); }); }
/** * Scope of categories with no parents. * * @param \Illuminate\Database\Eloquent\Builder $query * * @return \Illuminate\Database\Eloquent\Builder */ public function scopeRoots($query) { return $query->whereNull('parent_category_id'); }
/** * Scope a query to only include activities that have no sign-up and not passed the current date. * * @param \Illuminate\Database\Eloquent\Builder $query the query to activities to be scoped * @return \Illuminate\Database\Eloquent\Builder */ public function scopeUnfilled($query) { $query->select('activities.*')->leftJoin('tasks', 'activities.activity_id', '=', 'tasks.activity_id')->where(function ($query) { $query->whereNull('tasks.approval')->orWhere(function ($orQuery) { $orQuery->whereNotIn('tasks.approval', ['pending', 'approved']); }); })->upcoming(); }
/** * @param $key * @return static */ public function whereNull($key) { return parent::whereNull($key); }