A query scope that restricts results to files bound to a specific field on the owner model.

@param Builder $query
@param string  $fieldName
@return mixed
500937
public function scopeOfField ($query, $fieldName)
  {
    $fieldName = str_segmentsLast ($fieldName, '.');
    return exists ($fieldName) ? $query->where ('group', $fieldName) : $query;
  }
937158
private function resolveOrLinks(Builder $query, $field, $value)
    {
        $filters = explode(':or:', $value);
        if (count($filters) > 1) {

            $that = $this;
            $query->where(function ($query) use ($filters, $field, $that) {
                $first = true;
                foreach ($filters as $filter) {
                    $verb = $first ? 'where' : 'orWhere';
                    $query->$verb(function ($query) use ($field, $filter, $that) {
                        $query = $that->resolveAndLinks($query, $field, $filter);
                    });
                    $first = false;
                }
            });
        }
        else {

            $query = $this->resolveAndLinks($query, $field, $value);

        }

        return $query;
    }
277478
public function scopePublished(Builder $query)
    {
        $field = 'status';
        if (in_array($field, (array) $this->translatable)) {
            $field .= '->'.config('app.locale');
        }

        return $query->where($field, '1');
    }
424822
public function scopeFor($query, $table)
    {
        if ($table instanceof Model) {
            $table = $table->getTable();
        }

        return $query->where('table_name', $table);
    }
187644
protected function user(Builder $query)
    {
        // We'll try to locate the user by their object guid,
        // otherwise we'll locate them by their username.
        $query
            ->where(Resolver::getDatabaseIdColumn(), '=', $this->getGuid())
            ->orWhere(Resolver::getDatabaseUsernameColumn(), '=', $this->getUsername());
    }
854171
public function filterQuery(QueryBuilder &$query, &$selects = null)
    {
        $model = $this->config->getDataModel();

        //if this field has a min/max range, set it
        if ($this->getOption('min_max')) {
            if ($minValue = $this->getOption('min_value')) {
                $query->where($model->getTable().'.'.$this->getOption('field_name'), '>=', $minValue);
            }

            if ($maxValue = $this->getOption('max_value')) {
                $query->where($model->getTable().'.'.$this->getOption('field_name'), '<=', $maxValue);
            }
        }
    }
732978
protected function buildQuery(Builder $query, $name)
    {
        $op = $this->getOperator();
        $value = $this->getValue();

        switch ($op) {
            case 'in':
                $query->whereIn($name, (array) $value);
                break;
            case 'between':
                $query->whereBetween($name, (array) $value);
                break;
            case 'like':
                $value .= '%';
                $query->where($name, $op, $value);
                break;
            default:
                $query->where($name, $op, $value);
        }
    }
889081
public function scopeSearch(Builder $query, ?string $keyword, ?array $columns = null): Builder
    {
        return $this->setupWildcardQueryFilter($query, $keyword ?? '', $columns ?? $this->getSearchableColumns());
    }
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());
        });
    }
220056
public function scopeFromLastFourWeeks(Builder $query)
    {
        return $this->fromDaysAgo(Carbon::now()->daysInMonth, Carbon::now()->endOfDay());
    }
822291
public function scopeWhereFullPath(Builder $query, string $path)
    {
        $itemSlugs = explode('/', $path);

        return $query->where('slug', '=', end($itemSlugs))
            ->get()
            ->filter(function ($item) use ($path) {
                return $item->full_path === str_start($path, '/');
            });
    }
662377
public function scopeWhereOwnedBy(Builder $query, CanBeOwnerContract $owner)
    {
        return $query->where($this->getOwnerForeignKey(), $owner->getKey());
    }
627062
protected function filterByRequestParameters(Builder $query, Request $request, array $availableFields): Builder
    {
        $givenFields = $this->getRequestParameters($request);

        foreach ($givenFields as $fieldName => $value) {
            $from = substr($fieldName, 0, -5);
            $to = substr($fieldName, 0, -3);

            if (in_array($from, $availableFields) && $value != '') {
                $query->where($from, '>=', $value);
            }

            if (in_array($to, $availableFields) && $value != '') {
                $query->where($to, '<=', $value);
            }

            if (in_array($fieldName, $availableFields)) {
                if (is_array($value)) {
                    $query->whereIn($fieldName, $value);
                } else {
                    if ($value === 'NOT_NULL') {
                        $query->whereNotNull($fieldName);
                    } elseif ($value === 'NULL') {
                        $query->whereNull($fieldName);
                    } else {
                        $query->where($fieldName, '=', $value);
                    }
                }
            }
        }

        return $query;
    }
358389
public function scopeOnlyCreatedBy(Builder $query, Model $user)
    {
        return $query->where(config('accountable.column_names.created_by'), $user->getKey());
    }
737348
public function scopeFiltersApplySelection(Builder $query, $selection)
    {
        if (! is_object($selection)) {
            $selection = app()->make($selection);
        }

        $filters = $selection->filters();

        return $this->scopeFiltersApply($query, $filters);
    }
929709
protected function search(Builder $query, Request $request): Builder
    {
        $phrase = $request->input('q');

        if (!$phrase || strlen($phrase) < $this->minimumSearchInputLength) {
            return $query;
        }

        if ($this->translationModel()) {
            return $this->searchQueryTranslations($query, $phrase);
        }

        return $this->searchQuery($query, $phrase);
    }
1175587
public function scopeSearch(Builder $query, array $search = [])
    {
        if (empty($search)) {
            return $query;
        }

        if (!array_intersect(array_keys($search), $this->searchable)) {
            return $query;
        }

        return $query->where($search);
    }