定制 guiu/filament-filter-presets 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

guiu/filament-filter-presets

Composer 安装命令:

composer require guiu/filament-filter-presets

包简介

A Filament plugin to save and load filter presets

README 文档

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Filter Presets Overview

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

  1. Step 1 - Select Filters
  2. Step 2 - Save Preset
  3. Step 3 - Load Preset

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

  1. Install the package via composer:
composer require guiu/filament-filter-presets
  1. Publish and run the migrations:
php artisan vendor:publish --tag=filament-filter-presets-migrations
php artisan migrate
  1. Optionally, you can publish the translations:
php artisan vendor:publish --tag=filament-filter-presets-translations

Usage

  1. Add the HasFilterPresets trait 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

  1. 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
  2. Buttons don't appear

    • Verify that you have added the HasFilterPresets trait
    • Check that you included ...static::getFilterPresetActions() in table actions
    • Clear Laravel cache: php artisan cache:clear
  3. 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:

  1. Fork the repository
  2. Create a branch for your feature (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. 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! ☕

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 我们能提供哪些服务?
定制开发 / 二次开发

基于 guiu/filament-filter-presets 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 14
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 8
  • 点击次数: 18
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 8
  • Watchers: 0
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-06-30