Scope the given query to where the ability's model is missing.

@param  \Illuminate\Database\Query\Builder  $query
@param  string  $modelName
@return void
480704
protected function scopeQueryToWhereModelIsMissing($query, $modelName)
    {
        $model = new $modelName;
        $table = $this->abilitiesTable();

        $query->where("{$table}.entity_type", $modelName);

        $query->whereNotIn("{$table}.entity_id", function ($query) use ($modelName) {
            $model = new $modelName;
            $table = $model->getTable();

            $query->from($table)->select($table.'.'.$model->getKeyName());
        });
    }
358389
public function scopeOnlyCreatedBy(Builder $query, Model $user)
    {
        return $query->where(config('accountable.column_names.created_by'), $user->getKey());
    }
828438
public function scopeWhereLiked($query, Model $model)
    {
        return $query->whereHas('likes', function ($query) use ($model) {
            $query->where('liked_by_id', $model->id);
            $query->where('liked_by_type', get_class($model));
        });
    }
1134561
protected function _scopeQuery(Query $query, $bundle = null)
    {
        $this->_initScopes();
        foreach ($this->_queryScopes as $scope) {
            if ($scope instanceof QueryScopeInterface) {
                $query = $scope->scope($query, $bundle);
            }
        }

        return $query;
    }
187886
private function addSelectionMethod(QueryBuilderResult $query, $methodName)
    {
        $findMethod = function () use ($query, $methodName) {

            $sth = $this->pdo->prepare($query->getSql());
            /** @noinspection PhpMethodParametersCountMismatchInspection */
            $sth->setFetchMode(\PDO::FETCH_CLASS, $this->entityClass->getName());
            try {
                $sth->execute(func_get_args());
            } catch (PDOException $e) {
                throw new DslSyntaxException('Failed to run query [' . $methodName . '] with parameters ' . print_r(func_get_args(), true));
            }

            switch ($query->getResultMode()) {
                case QueryBuilderResult::RESULT_SELECT_SINGLE:
                    return $sth->fetch();
                case QueryBuilderResult::RESULT_SELECT_MULTIPLE:
                    return $sth->fetchAll();
            }

            throw new DslSyntaxException('Result Mode ' . $query->getResultMode() . ' is not implemented', DATADO_ILLEGAL_RESULT_MODE);

        };

        $this->methods[$methodName] = \Closure::bind($findMethod, $this, get_class());
    }
521993
public function scopeRecentlyCreated(Builder $query, $limit = null)
    {
        $query->orderBy('created_at', 'desc');

        if ($limit)
        {
            $query->limit($limit);
        }

        return $query;
    }
941804
public function scopeByTagName($query, $tag_name)
	{
		// mormalize string
		$tag_name = app(TaggingUtility::class)->normalizeTagName(trim($tag_name));
		return $query->where('name', $tag_name);
	}
869741
protected function modifyRelationQueryForContext(Model $model, $query)
    {
        /** @var Relation $relation */
        $information = $this->getInformationRepository()->getByModel($model);

        if ( ! $information) {
            return $query;
        }

        // Deal with global scopes, if any
        $disableScopes = $information->meta->disable_global_scopes;

        if (true === $disableScopes || is_array($disableScopes)) {
            $query->withoutGlobalScopes(
                true === $disableScopes ? null : $disableScopes
            );
        }

        // Apply repository context, if any
        $strategy = $information->meta->repository_strategy;

        if ($strategy) {
            $strategy = $this->resolveContextStrategy($strategy);

            if ($strategy) {
                $query = $strategy->apply($query, $information);
            }
        }

        return $query;
    }
910905
public static function make($query, Model $model = null)
    {
        if ($query instanceof EloquentBuilder) {
            $model = $query->getModel();
            $query = $query->getQuery();
        }

        return new Joiner($query, $model);
    }
240014
public function apply(Builder $query)
    {
        $this->specificationSet->applyAll($query);
        $this->sortingSet->applyAll($query);
        $this->paramSet->apply($query);
    }
456463
public function scopeOwnedBy(Builder $query, Model $related, ?string $key = null): Builder
    {
        if (\is_null($key)) {
            $key = $related->getForeignKey();
        }

        return $query->where($key, $related->getKey());
    }
1319213
public function run(&$query, $model, $request)
    {
        $this->query = $query;
        $this->getAttributes($model);
        $this->parseRequest($request);

        return $this->query();
    }
1042020
public function scopeOnlyDeletedBy(Builder $query, Model $user)
    {
        return $query->where(config('accountable.column_names.deleted_by'), $user->getKey());
    }
1067401
public function scopeSearch(Builder $query, $name, $userId)
    {
        return $query->where('user_id', '=', $userId)->where('name', '=', $name);
    }
428991
public function scopeFiltersApply(Builder $query, $entity = null): Builder
    {
        if (! is_null($entity)) {
            try {
                $this->getEntity($entity);
            } catch (EntityTypeException $e) {
            }
        }

        return $this->filter($query);
    }
222876
public function applyToModelQuery($query, $table = null)
    {
        if (is_null($this->scope) || $this->onlyScopeRelations) {
            return $query;
        }

        if (is_null($table)) {
            $table = $query->getModel()->getTable();
        }

        return $this->applyToQuery($query, $table);
    }
186772
public function saveSearchResults(QueryModel $query)
    {
        $adapter = $this->getConnection();
        $table = $this->getMainTable();

        $numResults     = $query->getNumResults();
        $isSpellchecked = (int) $query->getIsSpellchecked();

        $saveData = [
            'store_id'        => $query->getStoreId(),
            'query_text'      => $query->getQueryText(),
            'num_results'     => $numResults,
            'is_spellchecked' => $isSpellchecked,
        ];

        $updateData = ['num_results' => $numResults, 'is_spellchecked' => $isSpellchecked];

        $adapter->insertOnDuplicate($table, $saveData, $updateData);
    }