ToggleFilter
A switch button that narrows the list with a query of your own, e.g. “My requests”.
use Anvil\Collection\Filters\ToggleFilter;use Anvil\Data\Model;
ToggleFilter::make('mine')->label('My requests') ->query(static fn (Model $requests) => $requests->where('budget_owner_id', auth()->id())),
ToggleFilter::make('overdue')->label('Overdue') ->query(static fn (Model $tasks) => $tasks->where('due_on <', date('Y-m-d'))->where('status', 'open')),Options
Section titled “Options”| Option | Effect |
|---|---|
query(fn (Model $model) => …) |
the condition when the switch is on (required, otherwise a LogicException) |
Plus label(); column() is not used.
Control
Section titled “Control”A button that stays pressed while the filter is on.
The closure receives the model of the collection after its tenant scope
and scopeQuery(), and adds conditions. They are wrapped in parentheses,
so orWhere() inside cannot widen the list beyond the other conditions.
Use the query builder only, never raw input; values from the request do
not reach the closure.
Workflows provide a ready switch: $workflow->myTasksFilter() shows the
records with an open task or decision for the logged in user, see
Workflows.
Saved views, presets and API
Section titled “Saved views, presets and API”'1' when on. API: filter[mine]=1.