omneo / plugin-filterable
Laravel Nova的过滤器指标卡。
Requires
- php: >=7.1.0
- laravel/nova: *
- orchestra/testbench: ^3.7
Requires (Dev)
- mockery/mockery: ^1.1
This package is auto-updated.
Last update: 2024-09-03 08:59:26 UTC
README
为您的Laravel Nova指标添加自定义过滤器。
安装
您可以通过composer将此包安装到使用Nova的Laravel应用中。
composer require beyondcode/nova-filterable-cards
用法
要将过滤器功能添加到您的Laravel Nova指标卡,您需要将一个Filterable
特质添加到您的指标中。
根据您的指标类型,这些是可用的特质
FilterableValue
FilterableTrend
FilterablePartition
例如,在您的自定义Nova值指标卡中
// in your Nova value metric card class: import Beyondcode\FilterableCard\FilterableValue; use FilterableValue;
定义过滤器
您可以通过向您的指标添加一个名为$filters
的新属性来定义您的卡片可用过滤器。这必须是一个数组,包含可用过滤器的名称以及此特定过滤器的属性。
示例
// in your filterable Nova metric card class: protected $filters = [ 'Firstname' => [ 'type' => 'text' ], 'Status' => [ 'type' => 'select', 'options' => [ 'all' => 'All', 'active' => 'Active', 'inactive' => 'Inactive' ], ] ];
使用定义方法定义过滤器
有时您可能希望通过数据库调用设置可用过滤器选项,或从配置中加载它们。为了启用此功能,您还可以使用以下命名约定定义过滤器选项:defineStudlyCaseFilterName
。
例如,如果您想添加并定义一个名为User Status
的自定义过滤器,可以这样做
// in your filterable Nova metric card class: protected $filters = [ 'Firstname' => [ 'type' => 'text' ], 'User Status' ]; public function defineUserStatus() { return [ 'type' => 'select', 'options' => [ 'all' => 'All', 'active' => 'Active', 'inactive' => 'Inactive' ], ]; }
可用过滤器类型
可用的过滤器类型有
选择
复选框
文本
电子邮件
URL
数字
以及可以应用于HTML <input>
标签的所有其他类型。
应用过滤器逻辑
要定义当用户使用模态窗口过滤自定义指标查询时,您需要定义自定义过滤器方法。命名约定与定义自定义过滤器选项类似。它是filterStudlyCaseFilterName
。
此方法接收一个查询构建器对象和过滤器输入的值。您可以为构建器类添加自己的查询并按需修改。只需确保返回查询对象即可。
示例
// in your filterable Nova metric card class: public function filterUserStatus($query, $status) { return $query->where('status', $status); }
测试
composer test
变更日志
有关最近更改的更多信息,请参阅变更日志。
贡献
有关详细信息,请参阅贡献。
安全
如果您发现任何安全问题,请通过电子邮件marcel@beyondco.de报告,而不是使用问题跟踪器。
致谢
许可
MIT许可证(MIT)。有关更多信息,请参阅许可文件。