pianzhou / laravel-query-filter
This is laravel extension packages
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
Install
You can add this library as a local, per-project dependency to your project using Composer:
composer require pianzhou/laravel-query-filter
Database Query Filter
Config app.php
Pianzhou\Laravel\Query\Filter\ServiceProvider::class,
Demoļ¼
// 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();