Custom filter schemas
You may use schema components to create custom filters. The data from the custom filter schema is available in the$data array of the query() callback:
The query() function can inject various utilities into the function as parameters.
query() function can inject various utilities into the function as parameters.Learn more about utility injection.
Field
$component
Filament\Forms\Components\Field
The current field component instance.
Data
$data
array<string, mixed>
The data from the filter's form fields.
Get function
$get
Filament\Schemas\Components\Utilities\Get
A function for retrieving values from the current form data. Validation is not run.
Livewire
$livewire
Livewire\Component
The Livewire component instance.
Eloquent model FQN
$model
?string<Illuminate\Database\Eloquent\Model>
The Eloquent model FQN for the current schema.
Operation
$operation
string
The current operation being performed by the schema. Usually
create, edit, or view.Query
$query
Illuminate\Database\Eloquent\Builder
The Eloquent query builder to modify.
Raw state
$rawState
mixed
The current value of the field, before state casts were applied. Validation is not run.
Eloquent record
$record
?Illuminate\Database\Eloquent\Model
The Eloquent record for the current schema.
State
$state
mixed
The current value of the field. Validation is not run.
Setting default values for custom filter fields
To customize the default value of a field in a custom filter schema, you may use thedefault() method:
Active indicators
When a filter is active, an indicator is displayed above the table content to signal that the table query has been scoped. By default, the label of the filter is used as the indicator. You can override this using theindicator() method:
indicateUsing() to display an active indicator.
Please note: if you do not have an indicator for your filter, then the badge-count of how many filters are active in the table will not include that filter.
Custom active indicators
Not all indicators are simple, so you may need to useindicateUsing() to customize which indicators should be shown at any time.
For example, if you have a custom date filter, you may create a custom indicator that formats the selected date:
Multiple active indicators
You may even render multiple indicators at once, by returning an array ofIndicator objects. If you have different fields associated with different indicators, you should set the field using the removeField() method on the Indicator object to ensure that the correct field is reset when the filter is removed:
Preventing indicators from being removed
You can prevent users from removing an indicator usingremovable(false) on an Indicator object: