平舟 / laravel-query-filter
这是 Laravel 扩展包
v1.0.1
2022-07-21 15:05 UTC
Requires
- php: >=7.2
Provides
- psr/log-implementation: 1.0.0 || 2.0.0 || 3.0.0
README
安装
您可以使用 Composer 将此库添加为本地、按项目依赖项到您的项目中
composer require pianzhou/laravel-query-filter
数据库查询过滤器
配置 app.php
Pianzhou\Laravel\Query\Filter\ServiceProvider::class,
示例:
// demo one
DemoModel::filter($request->get('name'), function(int $value) {
$this->where('name', 'like', $value);
}, \Pianzhou\Laravel\Query\Filter\Filter::MODE_NULL);
// demo two
DemoModel::filters($request->only('column1', 'column2', 'column3'))->get();
// demo three
DemoModel::filters($request->only('name'), function (\Pianzhou\Laravel\Query\Filter\Filter $filter) {
$filter->where('name', 'like')
->where('nickname', 'like');
})->get();
// demo four
DemoModel::filters($request->only('name'), function (\Pianzhou\Laravel\Query\Filter\Filter $filter) {
$filter->when('name', function (int $value) {
$this->where('name', 'like', $value);
})
->when('nickname', function (string $value) {
$this->where('nickname', 'like', $value);
}, \Pianzhou\Laravel\Query\Filter\Filter::MODE_NULL);
})->get();