Apply the scope to a given Eloquent query builder.

@param  \Illuminate\Database\Eloquent\Builder $builder
@param  \Illuminate\Database\Eloquent\Model $model

@return void
424774
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->where($model->getQualifiedStatusColumn(), '!=', Status::REJECTED);
        }

        $this->extend($builder);
    }
980829
public function remove(Builder $builder, Model $model)
    {
        $query      = $builder->getQuery();
        $column     = $model->getQualifiedPositionColumn();

        foreach ((array) $query->orders as $key => $order) {

            if ($order['column'] == $column) {
                $this->removeOrderBy($query, $key);
            }
        }
    }
1353995
public function remove(Builder $builder, Model $model)
    {
        $query      = $builder->getQuery();
        $columns    = $model->getQualifiedOrderByColumns();

        foreach ($columns as $column => $direction) {

            foreach ((array) $query->orders as $key => $order) {

                if ($order['column'] == $column) {
                    $this->removeOrderBy($query, $key);
                }
            }
        }
    }
66708
public function apply(QueryBuilder $builder)
    {
        $builder->where($this->name, $this->operation, $this->value);
    }
1061312
public function extend(EloquentBuilder $builder)
    {
        $builder->macro('searchable', function (EloquentBuilder $builder, $chunk = null) {
            $builder->chunk($chunk ?: config('scout.chunk.searchable', 500), function ($models) {
                $models->filter->shouldBeSearchable()->searchable();

                event(new ModelsImported($models));
            });
        });

        $builder->macro('unsearchable', function (EloquentBuilder $builder, $chunk = null) {
            $builder->chunk($chunk ?: config('scout.chunk.unsearchable', 500), function ($models) {
                $models->unsearchable();

                event(new ModelsFlushed($models));
            });
        });
    }
750677
private function beforeGet(Builder $builder): void {
    $this->remapBuilderColumns($builder);
    $this->remapWheres($builder);
  }
255817
public function apply(Builder $builder, Model $model): void
    {
        if (method_exists($model, 'shouldApplyApprovedFlagScope') && $model->shouldApplyApprovedFlagScope()) {
            $builder->where('is_approved', 1);
        }
    }
690160
public function scopeWithAnyTenants(Builder $builder, $tenants): Builder
    {
        $tenants = $this->prepareTenantIds($tenants);

        return $builder->whereHas('tenants', function (Builder $builder) use ($tenants) {
            $builder->whereIn('id', $tenants);
        });
    }
451612
public function remove(Builder $builder, Model $model)
    {
        $query = $builder->getQuery();

        foreach ((array)$query->wheres as $key => $where)
        {
            if ($where['column'] === $model->getTypeKeyName())
            {
                unset($query->wheres[$key]);

                $query->wheres = array_values($query->wheres);
            }
        }
    }
571948
public function apply(Builder $builder, Model $model): void
    {
        if (empty($this->role)) {
            return;
        }

        $builder->whereHas('roles', function ($query) {
            $query->whereIn('name', (array) $this->role);
        });
    }
114534
protected function applySorts(ModelQueryBuilder $builder): self
    {
        if ($this->hasSorts() === true) {
            $builder->addSorts($this->getSorts());
        }

        return $this;
    }
301519
public function apply(Builder $builder, Model $post)
    {
        $query = $builder->getQuery();
        $types = array_keys($post::getModels());
        $query->whereIn('type', $types);
    }
358389
public function scopeOnlyCreatedBy(Builder $query, Model $user)
    {
        return $query->where(config('accountable.column_names.created_by'), $user->getKey());
    }
240014
public function apply(Builder $query)
    {
        $this->specificationSet->applyAll($query);
        $this->sortingSet->applyAll($query);
        $this->paramSet->apply($query);
    }
874211
public function scopeUnordered(Builder $q)
    {
        $query = $q->getQuery();
        if ($query->orders) {
            $query->orders = null;
        }
    }
1249005
protected function applyColumnMapper(ModelQueryBuilder $builder): self
    {
        if ($this->hasColumnMapper() === true) {
            $builder->setColumnToDatabaseMapper($this->getColumnMapper());
        }

        return $this;
    }
1349579
protected function applyScopes(QueryBuilder $query, Model $model, $ignoreScopes = [])
    {
        // Verificar se deve ignorar todos os scopes
        if (in_array('*', $ignoreScopes)) {
            return;
        }

        // Carregar lista de scopes
        $class = get_called_class();
        $scopes = Arr::get(static::$scopes, $class, []);

        // Aplicar scopes
        foreach ($scopes as $sid => $scope) {
            // Verificar se deve ignorar scope especifico
            if (! in_array($sid, $ignoreScopes)) {
                $scope->apply($query, $model);
            }
        }
    }