Download the PHP package 16hands/filament-dynamic-filter without Composer
On this page you can find all versions of the php package 16hands/filament-dynamic-filter. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download 16hands/filament-dynamic-filter
More information about 16hands/filament-dynamic-filter
Files in 16hands/filament-dynamic-filter
Package filament-dynamic-filter
Short Description Dynamic table filters for Filament with caching, indicators and panel access control
License MIT
Homepage https://github.com/16hands/filament-dynamic-filter
Informations about the package filament-dynamic-filter
Filament Dynamic Filter
Dynamic select filters for Filament tables. For direct columns, options come from the current table query; relationship filters query the related model by default.
The Problem
If you've used DataTables before, you'll remember the column header filters that automatically populated with values
from the table data. Filament's built-in SelectFilter requires you to manually define options or query them separately
from an entire table/model.
This becomes a real pain with relationship managers. Say you have an Order resource with a LineItems relation
manager. You want to filter line items by product name, but only show products that actually exist in this order's
line items — not every product in the database.
This package gives you filters that pull their options from the current table query for direct columns, respecting any
existing filters or scopes already applied. Relationship filters default to querying the related model directly, but you
can override this with optionsQuery when you need custom constraints.
Installation
Usage
Multiple Selection
Lazy Option Loading (Searchable Only)
When lazy: true and searchable: true, options are empty until the user types. Search results are fetched on demand.
Large lists (recommended):
Short lists (preload is fine):
Relationship Filters
For filtering through relationships using whereHas:
By default, relationship filters query the related model directly (no joins) so options and search work out of the box.
You can override this with optionsQuery if you need custom constraints:
Panel Access Control
Restrict filters to specific panels:
How It Works
The filter grabs the current table query (with all existing filters/scopes applied), plucks distinct values for the specified column when possible, and uses those as select options. Results are cached per column with a configurable TTL and scope.
Handles Carbon dates and PHP enums automatically — dates display as d/m/Y but filter as Y-m-d, enums use their
getLabel() method for display.
Parameters
DynamicFilter::make() and DynamicFilter::multiple()
| Parameter | Type | Description |
|---|---|---|
name |
string | Filter name (must be unique) |
column |
string | Dot-notation path to pluck from results (e.g. relation.field) |
queryColumn |
string | Database column for the where clause (e.g. table.field) |
placeholder |
?string | Select placeholder text |
label |
?string | Filter label |
searchable |
bool | Enable search in select (default: false) |
lazy |
bool | Defer options until search (requires searchable; default: false) |
panels |
?array | Restrict to specific panel IDs |
optionsMap |
?array | Map of raw values to display labels |
formatOption |
?callable | Formatter callback: fn ($value): array|string|null |
optionsQuery |
?callable | Provide a custom options Builder or Collection: fn (HasTable $livewire, Builder $query) (distinct/limit apply to Builders) |
DynamicFilter::relationship() adds:
| Parameter | Type | Description |
|---|---|---|
relationship |
string | Relationship name for whereHas |
relationshipColumn |
string | Column within the relationship |
multiple |
bool | Allow multiple selection (default: false) |
It also supports all base parameters above (including optionsQuery).
Configuration
Publish the config if you'd like to tune caching:
When using tenant scope, provide a tenant key or resolver in your config (otherwise caching is skipped for safety):
Caching Notes
- Options are cached per column using a distinct query when possible.
- If a distinct query fails, the filter falls back to
$query->get()->pluck($column). - Exceptions do not write to cache; they return an empty options list.
max_optionscaps the number of options returned.
Requirements
- PHP 8.2+
- Filament 4.x or 5.x
License
MIT
Credits
All versions of filament-dynamic-filter with dependencies
filament/tables Version ^4.0|^5.0
spatie/laravel-package-tools Version ^1.16