1. Go to this page and download the library: Download grixu/query-builder-filters library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
grixu / query-builder-filters example snippets
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();
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();
use Grixu\QueryBuilderFilters\StartsWithFilter;
// GET /users?filter[some]=93
$users = QueryBuilder::for(User::class)
->allowedFilters([
AllowedFilter::custom('some', new StartsWithFilter(), 'some'),
])
->get();
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();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.