degecko/laravel-nova-multifilter
Composer 安装命令:
composer require degecko/laravel-nova-multifilter
包简介
Combine multiple filter columns into a single Nova filter panel
README 文档
README
Combine multiple filter columns into a single Nova filter panel. Supports select dropdowns, text search, date ranges, number ranges, bitwise flags, and custom filter handlers.
Installation
composer require degecko/laravel-nova-multifilter
The service provider and assets are registered automatically via Laravel's package discovery.
Building Assets
npm install npm run prod
During development:
npm run watch
Usage
In your Nova resource's filters() method:
use DeGecko\NovaMultiFilter\MultiFilter; public function filters(NovaRequest $request): array { return [ new MultiFilter('Search', [ 'name' => '%w%', // LIKE search (word-boundary aware) 'email' => '%#%', // LIKE search (contains) 'status' => ['active', 'inactive'], // Select dropdown 'created_at' => ['from' => null, 'to' => null], // Date range ]), ]; }
Column Types
Select Dropdown
Pass an array of options. Use a flat array for value-only options, or an associative array for value => label pairs:
// Flat array — values are used as both the option value and label 'status' => ['active', 'inactive', 'banned'], // Associative — keys are stored, values are displayed 'role' => ['admin' => 'Administrator', 'editor' => 'Editor', 'user' => 'User'],
Text Search (LIKE)
Use a string pattern where # is replaced with the user's input:
'name' => '%w%', // Word-boundary search (splits on non-alphanumeric) 'email' => '%#%', // Simple contains 'phone' => '#%', // Starts with
The %w% pattern is special: it splits the input on non-alphanumeric characters and wraps each part with %, giving word-boundary-aware matching. For example, searching "John Doe" becomes %John%Doe%.
Date Range
Pass from/to keys to render two date pickers. Either bound is optional — leaving one empty creates an open-ended range:
'created_at' => ['from' => null, 'to' => null], 'updated_at' => ['from' => null, 'to' => null],
Number Range
Add 'type' => 'range' to render number inputs instead of date pickers:
'age' => ['from' => null, 'to' => null, 'type' => 'range'], 'price' => ['from' => null, 'to' => null, 'type' => 'range'],
Bitwise Flags
For integer columns storing bitwise flags. Labels are auto-formatted from the keys:
'permissions' => ['bitwise', [ 'can_edit' => 1, 'can_delete' => 2, 'can_publish' => 4, ]],
Column Aliases
Prefix a column with a different display name using as:
'email as E-mail' => '%#%', 'created_at as Registered' => ['from' => null, 'to' => null],
The part before as is used for the query; the part after is displayed as the label.
Composing with Nova Filters
You can pass existing Nova filter instances directly as columns. Their options will be extracted and their apply() method will be called when the value changes:
use App\Nova\Filters\StatusFilter; use App\Nova\Filters\CategoryFilter; new MultiFilter('Filters', [ 'status' => new StatusFilter, 'category' => new CategoryFilter, 'name' => '%w%', ]),
Custom Handlers
Register custom handler callbacks for columns that need special query logic:
(new MultiFilter('Search', [ 'name' => '%w%', 'active' => ['Yes', 'No'], ]))->handlers([ 'active' => fn($value, $query) => $query->where('is_active', $value === 'Yes'), ]),
Defaults
Set default filter values that are applied on page load:
(new MultiFilter('Filters', [ 'status' => ['active', 'inactive', 'banned'], 'role' => ['admin', 'editor', 'user'], ]))->defaults([ 'status' => 'active', ]),
Query Tap
Apply a scope or constraint to all filtered queries via the tap parameter:
// Scope to current tenant new MultiFilter('Search', $columns, tap: fn($q) => $q->where('tenant_id', auth()->user()->tenant_id)), // Include soft-deleted records new MultiFilter('Search', $columns, tap: fn($q) => $q->withTrashed()),
Debugging
Chain ->log() to output the raw SQL query to the Laravel log after filters are applied:
(new MultiFilter('Search', $columns))->log(),
Full Example
use DeGecko\NovaMultiFilter\MultiFilter; use App\Nova\Filters\StatusFilter; public function filters(NovaRequest $request): array { return [ (new MultiFilter('User Search', [ 'name' => '%w%', 'email as E-mail' => '%#%', 'phone' => '#%', 'status' => new StatusFilter, 'role' => ['admin' => 'Admin', 'editor' => 'Editor', 'user' => 'User'], 'created_at as Registered' => ['from' => null, 'to' => null], 'age' => ['from' => null, 'to' => null, 'type' => 'range'], 'permissions' => ['bitwise', ['can_edit' => 1, 'can_delete' => 2, 'can_publish' => 4]], ], tap: fn($q) => $q->where('tenant_id', auth()->user()->tenant_id))) ->defaults(['role' => 'user']) ->handlers([ 'custom' => fn($value, $query) => $query->whereHas('profile', fn($q) => $q->where('bio', 'like', "%$value%")), ]) ->log(), ]; }
How It Works
The MultiFilter renders all columns in a single horizontal filter panel. Each column type (select, text, date range, bitwise) gets the appropriate input widget. Changes are debounced (100ms) and applied as a combined filter value.
On the backend, each column's value is applied to the query based on its type:
- Arrays -
where($column, $value)or date range withwhereDate - Strings -
where($column, 'like', $pattern) - Bitwise -
whereRaw("$column & ?", [$value]) - Handlers - delegated to the callback or Nova filter's
apply()method
License
MIT
degecko/laravel-nova-multifilter 适用场景与选型建议
degecko/laravel-nova-multifilter 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 14 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 04 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「admin」 「filter」 「nova」 「laravel」 「multi-filter」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 degecko/laravel-nova-multifilter 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 degecko/laravel-nova-multifilter 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 degecko/laravel-nova-multifilter 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Laravel Nova card that shows you your system information.
A Laravel Nova card.
Nova searchable filter for belongsTo relationships.
2lenet/EasyAdminPlusBundle
A Laravel Nova package for publishable fields
A Laravel Nova package for translatable fields
统计信息
- 总下载量: 14
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 40
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-04-13