guiu/filament-filter-presets
Composer 安装命令:
composer require guiu/filament-filter-presets
包简介
A Filament plugin to save and load filter presets
README 文档
README
This package allows users to save and load predefined filter configurations in Filament resources. It is especially useful when:
- You need quick access to specific combinations of filters that you frequently use
- You want to create predefined filters for different scenarios or use cases
- You wish to set default filters that are automatically applied when a list is loaded
- You want to share filter configurations among different users of the system
With this module, you can:
- Save your custom filters with a name and description
- Quickly load previously saved filters
- Set default filters
- Manage your saved filters (delete, edit, set as default)
Step by Step
Prerequisites
Before installing this package, make sure your project meets the following requirements:
- PHP 8.1 or higher
- Laravel 10.0 or higher
- Filament 3.0 or higher
Installation
- Install the package via composer:
composer require guiu/filament-filter-presets
- Publish and run the migrations:
php artisan vendor:publish --tag=filament-filter-presets-migrations php artisan migrate
- Optionally, you can publish the translations:
php artisan vendor:publish --tag=filament-filter-presets-translations
Usage
- Add the
HasFilterPresetstrait to your List Resource page (not in the main Resource):
namespace App\Filament\Resources\YourResource\Pages; use Filament\Resources\Pages\ListRecords; use Guiu\FilamentFilterPresets\Traits\HasFilterPresets; class ListYourResource extends ListRecords { use HasFilterPresets; protected function getHeaderActions(): array { return [ Actions\CreateAction::make(), ...static::getFilterPresetHeaderActions(), ]; } }
Important:
- The trait must be added to the List class that extends
ListRecords - Add the filter preset actions in the
getHeaderActions()method (NOT in the table configuration) - Do NOT add the trait to the main Resource class
Features
- Save filters with name and description
- Mark filters as default
- Load saved filters
- Manage filters (delete, set as default)
Advanced Customization
Button Customization
You can customize the appearance of buttons by overriding the following methods:
protected static function getSaveFilterButtonLabel(): string { return 'Save filter'; } protected static function getLoadFilterButtonLabel(): string { return 'Load filter'; } protected static function getSaveFilterModalTitle(): string { return 'Save filter configuration'; } protected static function getLoadFilterModalTitle(): string { return 'Load filter configuration'; }
Integration with Other Plugins
You can integrate this package with other Filament plugins. For example, with the export plugin:
use Filament\Tables\Actions\ExportAction; public static function table(Table $table): Table { return $table ->headerActions([ ...static::getFilterPresetActions(), ExportAction::make() ->beforeExporting(function (Builder $query) { // Apply saved filters before exporting if ($preset = static::getDefaultPreset()) { $query = static::applyPresetFilters($query, $preset); } return $query; }) ]); }
Custom Actions
You can add custom actions to presets:
protected static function getFilterPresetActions(): array { return [ ...parent::getFilterPresetActions(), Action::make('duplicatePreset') ->label('Duplicate') ->icon('heroicon-o-duplicate') ->action(fn (FilterPreset $record) => static::duplicatePreset($record)), ]; }
Troubleshooting
Common Issues
-
Filters are not saving correctly
- Verify that you have run the migrations
- Check that you have write permissions to the database
- Make sure filters don't contain too large data
-
Buttons don't appear
- Verify that you have added the
HasFilterPresetstrait - Check that you included
...static::getFilterPresetActions()in table actions - Clear Laravel cache:
php artisan cache:clear
- Verify that you have added the
-
Error loading default filters
- Verify that the default filter exists
- Check that filter fields still exist in the model
- Clear config cache:
php artisan config:clear
Solutions
# Regenerate composer autoload composer dump-autoload # Clear all caches php artisan optimize:clear # Verify database integrity php artisan migrate:status # If needed, refresh migrations (CAUTION: this will delete data!) php artisan migrate:fresh
Contributing
If you want to contribute to the development of this package, please:
- Fork the repository
- Create a branch for your feature (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
This package is licensed under the MIT license.
Support
If you discover any issues or have questions, please create an issue on GitHub.
Made with ❤️ for the Filament community
☕ Buy me a coffee
If you like this project and it has been useful to you, you can buy me a coffee! ☕
guiu/filament-filter-presets 适用场景与选型建议
guiu/filament-filter-presets 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 14 次下载、GitHub Stars 达 8, 最近一次更新时间为 2025 年 06 月 30 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「ui」 「laravel」 「filters」 「tables」 「presets」 「filament」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 guiu/filament-filter-presets 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 guiu/filament-filter-presets 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 guiu/filament-filter-presets 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
(ru) language pack for the Static Info Tables providing localized names for countries, currencies and so on.
(Ukrainian) language pack for the Static Info Tables providing localized names for countries,currencies and so on.
Simple filters for laravel
Turkish (tr) language pack for the Static Info Tables providing localized names for countries.
Display multiple images as a stack in your Filament tables
Livewire Filters is a series of Livewire components that provide you with the tools to do live filtering of your data from your own Livewire components.
统计信息
- 总下载量: 14
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 8
- 点击次数: 18
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-06-30



