Apply the scope to a given Eloquent query builder.

@param  \Illuminate\Database\Eloquent\Builder $builder
@param  \Illuminate\Database\Eloquent\Model $model
@return void
18476
public function apply(Builder $builder, Model $model)
    {
        if ($model->getTypeKey())
        {
            $builder->where(
                $model->getTypeKeyName(),
                $model->getTypeKey()
            );
        }
    }
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);
        });
    }
1296751
public function apply(Builder $builder, Model $model): void
    {
        if (method_exists($model, 'shouldApplyVerifiedAtScope') && $model->shouldApplyVerifiedAtScope()) {
            $builder->whereNotNull('verified_at');
        }
    }
529504
public function apply(Builder $builder, Model $model)
    {
        if (method_exists($model, 'shouldApplyBannedAtScope') && $model->shouldApplyBannedAtScope()) {
            return $builder->whereNull('banned_at');
        }

        return $builder;
    }
1229356
public function apply(Builder $builder, Model $model)
    {
        if (!$this->hasVersionJoin($builder, $model->getVersionTable())) {
            $builder->join($model->getVersionTable(), function($join) use ($model) {
                $join->on($model->getQualifiedKeyName(), '=', $model->getQualifiedVersionKeyName());
                $join->on($model->getQualifiedVersionColumn(), '=', $model->getQualifiedLatestVersionColumn());
            });
        }

        $this->extend($builder);
    }
850787
public function apply(Builder $query, Model $model)
    {
        Models::scope()->applyToModelQuery($query, $model->getTable());
    }
1201870
public function remove(Builder $builder, Model $model)
    {
        $builder->withoutGlobalScope($this);

        $column = $model->getQualifiedStatusColumn();
        $query = $builder->getQuery();

        $bindingKey = 0;

        foreach ((array)$query->wheres as $key => $where) {
            if ($this->isModerationConstraint($where, $column)) {
                $this->removeWhere($query, $key);

                // Here SoftDeletingScope simply removes the where
                // but since we use Basic where (not Null type)
                // we need to get rid of the binding as well
                $this->removeBinding($query, $bindingKey);
            }

            // Check if where is either NULL or NOT NULL type,
            // if that's the case, don't increment the key
            // since there is no binding for these types
            if (!in_array($where['type'], ['Null', 'NotNull'])) $bindingKey++;
        }

    }
410753
public function createFromBuilder(Builder $builder)
    {
        $this->model = $builder->getModel();
        $this->query = $builder;

        $this->build();

        return $this;
    }
1370651
protected function addWithClosed(Builder $builder): void
    {
        $builder->macro('withClosed', function (Builder $builder) {
            return $builder->withoutGlobalScope($this);
        });
    }
66708
public function apply(QueryBuilder $builder)
    {
        $builder->where($this->name, $this->operation, $this->value);
    }
358389
public function scopeOnlyCreatedBy(Builder $query, Model $user)
    {
        return $query->where(config('accountable.column_names.created_by'), $user->getKey());
    }
312969
public function scopeOfOwner(Builder $builder, Model $owner): Builder
    {
        return $builder->where('owner_type', $owner->getMorphClass())->where('owner_id', $owner->getKey());
    }
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);
            }
        }
    }
301519
public function apply(Builder $builder, Model $post)
    {
        $query = $builder->getQuery();
        $types = array_keys($post::getModels());
        $query->whereIn('type', $types);
    }
339242
public function apply(Builder $builder)
    {
        $model = $builder->getModel();

        $builder->whereNull($model->getQualifiedDeletedAtColumn());

        $this->extend($builder);
    }
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);
    }
821728
public function apply(Builder $builder, Model $model)
    {
        if (!UserUtils::hasDisplayAllStatus())
        {
            $builder->where($model->getQualifiedStatusColumn(), true);
        }
        $this->extend($builder);

    }