Components
Media Library
Integrations
Filters
You can use filters in the media library to narrow down the selection of media items based on specific criteria.
Default filters
By default, the Media Library comes with the following filters:
Date
The created at filter allows you to filter media items by their upload/creation date:
Size
The size filter allows you to filter media items by their size:
Type
The mime type filter allows you to filter media items by their mime type:
Tags
The tags filter allows you to filter media items by their associated tags:
Custom filter
Creating a custom filter requires several steps to link it up correctly with the driver. In this example, we'll create a filter that allows users to filter media items based on whether they are marked as "featured".
Create filter
First, the filter-class must be created. This class is responsible for rendering the filter form, generating indicators and defining which modifications should be applied when the filter is used.
Register filter
Next, the filter must be registered on the library:
Create modification
Next, a modification needs to be created. A modification is returned from the filter, and is responsible for holding the "information" about what needs to be scoped:
Apply modification
Finally, it must be told to the driver how to exactly apply the above modification:
If you have not yet made the choice for a driver, consider using the default recommended Media Library Item-driver. As this driver is database-based, you can easily add custom columns to the
filament_media_library-table where you can conveniently store such extra meta-data as whether an item is featured.
This way, the filter will determine what modifications need to be applied when retrieving the media results, and the driver knows how to interpret these modifications and will apply them.
In the UI, the filter will now show up as such:
And when applied:
You can read more about modifications and their types in the Modifications documentation.