Skip to content

Filter Options ​

Scope options set the values scopes start with, replace their default queries with SQL or model scopes, shape the options of a group and link scopes together. The scope properties and scope types list every option in one place.

The filters on this page ​

Most examples are built like those on Scope Types: a filter of posts with the scopes from its own YAML file, bound to a list of posts. The empty option, dependent scopes, search and primary row examples show their own methods.

php
/**
 * makeOptionFilters builds a filter for each example whose options are all in its YAML file, bound to a list of posts.
 *
 * @return array<string, array{filter: Filter, list: Lists}>
 */
protected function makeOptionFilters(): array
{
    $examples = [];

    foreach (['defaults', 'conditions', 'group-options', 'date-options', 'number-options', 'names'] as $name) {
        $list = $this->makeFilteredPosts(Str::camel($name).'List');

        $filter = Filter::make(
            alias: Str::camel($name).'Filter',
            model: new Post,
            scopes: "~/resources/ui/reference/filters/options/{$name}.yaml",
        );

        $filter->bindToListWidget($list);

        $examples[$name] = ['filter' => $filter, 'list' => $list];
    }

    return $examples;
}

/**
 * makeFilteredPosts builds a list of posts for a filter to filter.
 */
protected function makeFilteredPosts(string $alias): Lists
{
    return Lists::make(
        alias: $alias,
        model: new Post,
        columns: '~/resources/ui/reference/filters/posts.yaml',
        recordsPerPage: 5,
        noRecordsMessage: 'No posts match the filter.',
        customPageName: false,
    );
}

Default values ​

default sets the value a scope starts with, so these posts start without the archived ones and with only the approved status. A change to a scope lasts for the session, and Clear Filters goes back to the defaults.

A checkbox takes 1 to start on, a switch 1 or 2 for its first or second state, a dropdown the value of an option and a group a list of values. The popover types take an array of their values, such as a condition and a value, or condition: inLast, count: 30 and unit: days for a date scope that starts on the last 30 days. The trashed type takes with or only.

yaml
scopes:
    hide_archived:
        label: Hide archived
        type: checkbox
        default: 1
        conditions: status <> 'archived'

    status:
        label: Status
        type: dropdown
        emptyOption: Any status
        default: approved
        options:
            draft: Draft
            review: In Review
            approved: Approved
            archived: Archived

Conditions ​

conditions replaces a scope's default query with SQL.

  • A checkbox takes one condition, applied while it is on, and a switch takes a list of two, one for each state.
  • A dropdown takes one condition, where :value is the picked option, and a group takes one where :value is the picked values, quoted and separated by commas.
  • Number, date and text scopes take one condition for each choice they offer, keyed by its name, where true keeps the default query. They offer only the named choices, and with a single choice the popover shows it as a label in place of a select, like the Address scope here. Without conditions they offer every choice in the table but notEquals, which a date scope offers when it is named.
ChoiceLabelScope typesSQL placeholders
inLastis in the lastdate:after, :afterDate, :before, :beforeDate, the first and last day of the period
inNextis in the nextdateas inLast
equalsis equal to, or is on for a datenumber, date, text:value, and :valueDate for a date
notEqualsis not ondate:value, :valueDate
betweenis betweennumber, datenumber: :min, :max. Date: :after, :afterDate, :before, :beforeDate
greateris greater thannumber:value
lesseris less thannumber:value
afteris on or afterdate:value, :valueDate
beforeis before or ondate:value, :valueDate
containscontainstext:value
emptyis emptynumber, date, textnone
notEmptyis not emptynumber, date, textnone

In a date condition, :value, :after and :before hold the start of their day in the app timezone, while :valueDate, :afterDate and :beforeDate hold the date alone. A condition that takes in the whole last day compares the date alone, as in date(published_at) <= :beforeDate.

yaml
scopes:
    popular:
        label: Popular
        type: dropdown
        emptyOption: Any views
        conditions: views >= :value
        options:
            1000: 1,000 views or more
            5000: 5,000 views or more

    comment_count:
        label: Comments
        type: number
        conditions:
            greater: (select count(*) from comments where comments.post_id = posts.id) >= :value
            lesser: (select count(*) from comments where comments.post_id = posts.id) <= :value

    review_on:
        label: Review Date
        type: date
        conditions:
            before: review_on <= :valueDate
            after: review_on >= :valueDate

    slug:
        label: Address
        type: text
        conditions:
            contains: true

Empty option ​

emptyOption on a group adds an option for the records with no value, here the posts without tags. Picked with other options, it keeps the records with any of them or with none. It widens only its own scope, so the published switch and the search box still apply. On a dropdown, emptyOption is the option that applies no filter instead.

php
/**
 * makeEmptyOptionFilter filters by tag, offering an option for the untagged posts.
 */
protected function makeEmptyOptionFilter(Lists $list): Filter
{
    $filter = Filter::make(
        alias: 'emptyOptionFilter',
        model: new Post,
        scopes: '~/resources/ui/reference/filters/options/empty-option.yaml',
    );

    $filter->bindToListWidget($list);

    return $filter;
}

/**
 * makeEmptyOptionToolbar searches the same list as the filter.
 */
protected function makeEmptyOptionToolbar(Lists $list): Toolbar
{
    $toolbar = Toolbar::make(
        alias: 'emptyOptionToolbar',
        search: ['prompt' => 'Search posts...'],
    );

    $toolbar->bindToListWidget($list);

    return $toolbar;
}
yaml
scopes:
    published:
        label: Published
        type: switch
        conditions:
            - published = false
            - published = true

    tags:
        label: Tags
        type: group
        nameFrom: name
        emptyOption: Untagged

Group options ​

modelClass names the model whose records are a group's options, in place of the model of the relation the scope is named after. optionsScope applies one of that model's scopes to the options, here offering only the categories that hold posts. matchMode: toggle adds an Exclude selected switch to the popover, which keeps the records without the picked options, while matchMode: exclude always excludes them. While a group excludes, its chip shows a cross before the count.

yaml
scopes:
    category:
        label: Category
        type: group
        modelClass: App\Models\Category
        nameFrom: name
        optionsScope: hasPosts
        matchMode: toggle
php
/**
 * scopeHasPosts limits the query to categories holding at least one post, used by the posts category filter.
 */
public function scopeHasPosts($query)
{
    return $query->has('posts');
}

Date picker options ​

minDate and maxDate limit the dates that can be picked, here to 2026, and yearRange sets how many years either side the calendar's year view offers. firstDay: 1 starts the week on Monday in place of the locale's first day, and showWeekNumber numbers the weeks. useTimezone: false compares the picked days with the stored dates as they are, in place of reading them in the viewer's timezone.

yaml
scopes:
    published_at:
        label: Published
        type: date
        minDate: '2026-01-01'
        maxDate: '2026-12-31'
        firstDay: 1
        showWeekNumber: true
        yearRange: 1
        useTimezone: false

Number options ​

format shows the numbers in a number scope's inputs with thousands separators, as on a number field: true groups the digits, and an array takes decimals, grouping and locale. The inputs still post the plain number, so the conditions and model scopes receive 2500, not 2,500.

prefix and suffix show text inside the inputs, such as $ for a price, and prefixIcon and suffixIcon show an icon, as on a field. The chip shows the value formatted, with the prefix and suffix text: a symbol such as $ or % joins the number, while a word is spaced from it, so the views here read ≥ 2,500 views. Icons show only in the inputs.

yaml
scopes:
    views:
        label: Views
        type: number
        format: true
        suffix: views

    id:
        label: ID
        type: numberrange
        prefixIcon: ph ph-hash

Names, labels and order ​

valueFrom filters a column with a name other than the scope's, here published for the live scope, and shortLabel replaces the label in the bar. Scopes show in the order of the file, which before and after change, so the status scope here comes before the views, and order sets a position as a number. cssClass adds a class to the scope.

yaml
scopes:
    live:
        label: Published posts only
        shortLabel: Live
        type: checkbox
        valueFrom: published

    views:
        label: Views
        type: number
        cssClass: fst-italic

    status:
        label: Status
        type: group
        before: views
        options:
            draft: Draft
            review: In Review
            approved: Approved
            archived: Archived

Model scopes and dependent scopes ​

modelScope runs a model scope in place of the default query. The scope method receives the query and the filter scope, whose value holds the picked value, here filtering the users by their email domain. modelScope also takes a static method as Class::method, called with the query and the scope.

dependsOn links scopes together: when the named scope changes, this one is cleared and rendered again, so a picked name resets when the domain does. On a group with a modelClass, an optionsMethod given as a method name is called on that model with every scope and its current value, so it can narrow its options by another scope, as in $scopes->domain->value.

php
/**
 * makeFilteredUsers builds a list of users for the dependent scopes to filter.
 */
protected function makeFilteredUsers(): Lists
{
    return Lists::make(
        alias: 'dependsList',
        model: new User,
        columns: '~/resources/ui/reference/filters/users.yaml',
        recordsPerPage: 5,
        noRecordsMessage: 'No users match the filter.',
        customPageName: false,
    );
}

/**
 * makeDependsFilter filters the users by a model scope and a scope that resets when it changes.
 */
protected function makeDependsFilter(Lists $list): Filter
{
    $filter = Filter::make(
        alias: 'dependsFilter',
        model: new User,
        scopes: '~/resources/ui/reference/filters/options/depends.yaml',
    );

    $filter->bindToListWidget($list);

    return $filter;
}
yaml
scopes:
    domain:
        label: Email Domain
        type: dropdown
        emptyOption: All domains
        modelScope: applyDomain
        options:
            example.com: example.com
            example.org: example.org
            example.net: example.net

    name:
        label: Name
        type: group
        optionsMethod: App\Models\User::getNameGroupOptions
        dependsOn: domain
yaml
columns:
    name:
        label: Name

    email:
        label: Email
php
/**
 * Filter users by email domain, used by the "Email Domain" scope on the Filter Options reference page.
 */
public function scopeApplyDomain($query, $scope)
{
    return $query->where('email', 'like', '%@'.$scope->value);
}
php
/**
 * Options for the "Name" group filter scope.
 *
 * @return array<string, string>
 */
public static function getNameGroupOptions(): array
{
    return static::query()->orderBy('name')->pluck('name', 'name')->all();
}

Scope values ​

A model scope reads the scope's value from these properties.

Scope typeProperties
checkboxvalue, set while the checkbox is on.
switchvalue: 1 or 2 for the first or second state.
dropdownvalue: the picked option.
groupvalue: the picked values. mode: include or exclude.
datecondition, with value, or after and before for between, or count and unit (days, weeks, months or years) for in the last and in the next. The empty conditions carry the condition alone.
numbercondition, with value, or min and max for between. The empty conditions carry the condition alone.
textcondition, with value unless the condition is empty or not empty.
trashedvalue: with or only.

search adds a search box after the scopes, configured like a toolbar search, and setupHandler adds the list setup icon beside it. bindToListWidget() connects the search to the list, so the filter can carry the search and list setup a toolbar would otherwise hold. The search keeps its term for the session, and Clear Filters leaves it alone.

php
/**
 * makeSearchFilter adds a search box and the list setup icon after the scopes.
 */
protected function makeSearchFilter(Lists $list): Filter
{
    $filter = Filter::make(
        alias: 'searchFilter',
        model: new Post,
        scopes: '~/resources/ui/reference/filters/options/search.yaml',
        search: ['prompt' => 'Search posts...'],
        setupHandler: $list->getEventHandler('onLoadSetup'),
    );

    $filter->bindToListWidget($list);

    return $filter;
}
yaml
scopes:
    status:
        label: Status
        type: dropdown
        emptyOption: Any status
        optionsMethod: App\Models\Post::listStatusColorOptions

    published:
        label: Published
        type: checkbox

primary: 'search' moves the search box and the list setup icon into a row of their own, above the scopes, where the search box fills the row in place of growing when focused. It needs a search to move.

php
/**
 * makePrimarySearchFilter gives the search box and the list setup icon a row of their own above the scopes.
 */
protected function makePrimarySearchFilter(Lists $list): Filter
{
    $filter = Filter::make(
        alias: 'primarySearchFilter',
        model: new Post,
        scopes: '~/resources/ui/reference/filters/options/search.yaml',
        search: ['prompt' => 'Search posts...'],
        setupHandler: $list->getEventHandler('onLoadSetup'),
        primary: 'search',
    );

    $filter->bindToListWidget($list);

    return $filter;
}

A dropdown as tabs ​

primary set to the name of a dropdown scope shows that scope as a row of tabs above the others, in place of its chip, while the search box and list setup stay with the other scopes. The scope keeps its options, default, saved value and query. The first tab applies no filter, labelled with the scope's emptyOption, or All without one, and the tabs keep the order of the options. The tabs share the row's width, and when there are too many to fit they keep their width and the row drag scrolls.

php
/**
 * makePrimaryTabsFilter shows the status dropdown as tabs in a row above the other scopes.
 */
protected function makePrimaryTabsFilter(Lists $list): Filter
{
    $filter = Filter::make(
        alias: 'primaryTabsFilter',
        model: new Post,
        scopes: '~/resources/ui/reference/filters/options/primary-tabs.yaml',
        search: ['prompt' => 'Search posts...'],
        setupHandler: $list->getEventHandler('onLoadSetup'),
        primary: 'status',
    );

    $filter->bindToListWidget($list);

    return $filter;
}
yaml
scopes:
    status:
        label: Status
        type: dropdown
        emptyOption: All statuses
        optionsMethod: App\Models\Post::listStatusColorOptions

    category:
        label: Category
        type: group
        nameFrom: name

    published:
        label: Published
        type: checkbox

Saved filters ​

The menu at the start of the bar keeps named sets of scope values. Save Filters saves the current values, under a new name or in place of an existing set picked below it, which turns Save into Update. Using one clears the other, and saving with a name already in use replaces that set. Saved Filters lists the sets in name order, with a check against the one the scopes match, and picking a set puts every scope back to its saved value, and the scopes the set leaves out to their default. Manage deletes sets. The search box is not part of a set.

The sets belong to the filter and are kept with the user preferences: in the session unless you bind a store of your own, as list setup describes. savedFilters: false leaves them out of the menu.