web-id / flan
FLAN - 像忍者一样过滤
0.1.0
2021-06-28 08:16 UTC
Requires
- php: ^7.4|^8.0
- friendsofphp/php-cs-fixer: ^3.0
- maatwebsite/excel: ^3.1
Requires (Dev)
- nunomaduro/larastan: ^0.6.13
- orchestra/testbench: ^6.0
- phpstan/phpstan: ^0.12.70
- phpunit/phpunit: ^9.3
- vlucas/phpdotenv: ^5.3
- dev-main
- 0.1.0
- 0.0.1
- dev-update-documentation
- dev-ch5754/tester-le-filtre-de-type-select
- dev-ch2977/modifier-l-organisation-des-inputs-dans-la
- dev-ch2983/bug-typo-dans-le-chemin-de-la-config-generee
- dev-ch2984/commencer-la-documentation-du-package
- dev-leo/fix_only_in_group_by
- dev-leo/fix_validator
- dev-francois/add-routes-service-provider
- dev-leo/starting
This package is auto-updated.
Last update: 2024-09-19 12:06:19 UTC
README
安装
使用composer安装此包。
composer require web-id/flan
FLAN使用Laravel Package Auto-Discovery,不需要您手动添加ServiceProvider。
使用发布命令将包配置复制到本地配置
php artisan vendor:publish --provider="WebId\Flan\FlanServiceProvider"
最后,运行过滤表的迁移
php artisan migrate
用法
您可以使用以下方式创建过滤器
php artisan filter:create User
或者最终只是Filter类
php artisan make:filter:class User
或者只是Filter配置
php artisan make:filter:config User
过滤器配置
您可以在config/FilterConfigs
文件夹中找到您的过滤器配置文件
任何字段类型的配置
return [ 'name' => 'myfilter', 'filters' => [ [ 'text' => 'Model ID', 'name' => 'id', 'active' => true, 'field' => [ 'type' => 'number', ], ], // [ ... ] ], ];
filters.*.text
是HTML输入标签
filters.*.name
是HTML输入的name属性filters.*.active
决定数据是否会在表中显示filters.*.filterable
决定是否为该列显示过滤器输入filters.*.field
包含应用于输入的选项filters.*.field.type
是输入类型,可以是以下之一:checkbox
、date
、number
、select
、text
filters.*.field.options
包含可用的选择列表。以下是一个示例
特定于select
类型的配置
filters.*.field.options
包含可用的选择列表。以下是一个示例
'options' => [ [ 'value' => '0', 'text' => 'Disabled', ], [ 'value' => '1', 'text' => 'Enabled', ], // [ ... ], ],
过滤器类
custom_select
定义属性
假设您正在定义一个BookFilter
类,并且想要格式化页数值
$this->setDefinition('number_of_pages', [ 'custom_select' => 'CONCAT(`number_of_pages`, " pages")', ]);
join
定义属性
假设您正在定义一个BookFilter
类,并且想要能够根据书籍作者的出生城市进行过滤,例如。
如果您想使用带有连接子句的自定义选择,可以在Filter类构造函数中这样做
$this->setDefinition('author_birth_city', [ 'join' => 'leftJoinAuthorsTable', 'custom_select' => '`authors`.`birth_city`', ]);
然后,您需要添加一个以join
参数命名的函数来应用查询的连接,例如
protected function leftJoinAuthorsTable(): void { $this->query->leftJoin( 'authors', 'books.author_id', '=', 'authors.id' ); }
致谢
许可证
MIT许可证(MIT)。请参阅许可证文件获取更多信息。