grixu / query-builder-filters
Set of filters for laravel-query-builder (made by Spatie)
1.2.2
2021-11-18 11:31 UTC
Requires
- php: ^7.3 || ^8.0
- illuminate/database: ^8.0
- spatie/laravel-query-builder: ^3.3.4 || ^4.0.0
Requires (Dev)
- brainmaestro/composer-git-hooks: ^2.8
- friendsofphp/php-cs-fixer: ^3.1
- nunomaduro/larastan: ^0.7.12 || ^1.0.0
- nunomaduro/phpinsights: ^2.0
- orchestra/testbench: ^6.0
- phpunit/phpunit: ^9.3
- spatie/x-ray: ^1.1
This package is auto-updated.
Last update: 2024-11-10 04:22:38 UTC
README
Set of filters for laravel-query-builder (made by Spatie)
Installation
You can install the package via composer:
composer require grixu/query-builder-filters
Usage
This is package is bunch of filters to sue with great package made by Spatie: laravel-query-builder. Below you can see an examples how to use each of 10 filters from this package.
DateAfterField, DateBeforeFilter, DateBetweenFilter
use Grixu\QueryBuilderFilters\DateAfterFilter; use Grixu\QueryBuilderFilters\DateBeforeFilter; use Grixu\QueryBuilderFilters\DateBetweenFilter; // In your Controller or HttpQueryBuilder class for the following request: // GET /users?filter[date_after]=2020-12-01 // GET /users?filter[date_before]=2020-12-01 // GET /users?filter[date_between]=2020-11-01,2020-12-01 $users = QueryBuilder::for(User::class) ->allowedFilters([ AllowedFilter::custom('date_after', new DateAfterFilter(), 'date_field_name'), AllowedFilter::custom('date_before', new DateBeforeFilter(), 'date_field_name'), AllowedFilter::custom('date_between', new DateBetweenFilter(), 'date_field_name'), ]) ->get();
GreaterThanFilter, GreaterOrEqualThanFilter, LowerThanFilter, LowerOrEqualThanFilter
use Grixu\QueryBuilderFilters\GreaterThanFilter; use Grixu\QueryBuilderFilters\GreaterOrEqualThanFilter; use Grixu\QueryBuilderFilters\LowerThanFilter; use Grixu\QueryBuilderFilters\LowerOrEqualThanFilter; // GET /users?filter[field_gt]=100 // GET /users?filter[field_gte]=100 // GET /users?filter[field_lt]=100 // GET /users?filter[field_lte]=100 $users = QueryBuilder::for(User::class) ->allowedFilters([ AllowedFilter::custom('field_gt', new GreaterThanFilter(), 'field'), AllowedFilter::custom('field_gte', new GreaterOrEqualThanFilter(), 'field'), AllowedFilter::custom('field_lt', new LowerThanFilter(), 'field'), AllowedFilter::custom('field_lte', new LowerOrEqualThanFilter(), 'field'), ]) ->get();
StartsWithFilter
use Grixu\QueryBuilderFilters\StartsWithFilter; // GET /users?filter[some]=93 $users = QueryBuilder::for(User::class) ->allowedFilters([ AllowedFilter::custom('some', new StartsWithFilter(), 'some'), ]) ->get();
IsNullFilter, NotNullFilter
use Grixu\QueryBuilderFilters\IsNullFilter; use Grixu\QueryBuilderFilters\NotNullFilter; // GET /users?filter[not_null]=some_field // GET /users?filter[is_null]=some_field $users = QueryBuilder::for(User::class) ->allowedFilters([ AllowedFilter::custom('is_null', new IsNullFilter()), AllowedFilter::custom('not_null', new NotNullFilter()), ]) ->get();
Testing
composer test
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email mateusz.gostanski@gmail.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.