Download the PHP package cognitas/query-filter without Composer

On this page you can find all versions of the php package cognitas/query-filter. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package query-filter

QueryFilter

License: MPL-2.0

The QueryFilter package is a Laravel query filtering package that allows you to build dynamic Eloquent filters using request URL parameters. It supports nested conditions, logical operators and sorting.

Installation

Install via Composer:

Usage

Inside your controller, import the Filter facade

and then call Filter::applyFilters() with:

The applyFilters method modifies the provided query builder object and returns a FilterResult object containing any errors encountered while parsing or applying filters.

Example:

The FilterResult object provides:

You can call the applyFilters method anytime, not just at the beginning. You can start with a static query, like querying all of the logged in user's posts and then filtering those further based on the input query filter. The parsed filters are added to the overall query (appended with the AND operator).

Filter syntax

A filter is defiened as a nested array of base filters combined with logical operators → AND, OR. Base filters are filters directly applied to some model's attribute.

PHP uses brackets to pass arrays in a URL, therefore if we do:

PHP will parse it as an associative array test:

Empty brackets get automatically enumareted to keys in the array. But we can define any key we want and we can also add multiple sets of brackets → nest arrays in array.

Inside brackets we therefore use:

This filter:

can be we written like so:

Let's use the query parameter filters for defining our filter. Each such parameter has the syntax:

filters[LOP][INDEX][LOP][INDEX]....[LOP|INDEX|empty]=base_filter

where LOP is the logical operator AND, OR, and the base filter has the syntax:

field:OP:value

With INDEX we specify the index or position of the operand in the previous logical expression -> we specify the position of the element in the array.

If we write

filters[AND][0]=base_filter1&filters[AND][1]=base_filter2

the first operand of the AND will be base_filter1 and the second operand will be base_filter2. There can be any number of operands.

Shorter syntax

We can replace:

filters[AND][0]=base_filter1
&filters[AND][1]=base_filter2
&filters[AND][2]=base_filter3

with:

filters[AND]=base_filter1;base_filter2;base_filter3

The filters will be split by the semicolon and will be joined by the logical AND operator.

Filter by related model

To filter by related model, for example filter posts based on the user's (creator's) name, the base_filter has this syntax:

relationship.(field:OP:value*field:OP:value*...)

Filters are seperated with the asterisk symbol *, and are joined by an AND operator.

To filter posts whose creator (user) has the name John, we would write

filters[AND][0]=user.(name:EQ:John)

Sorting

To sort (order) the result we add the query parameter:

filters[ORDER]=base_order;base_order;...

Where base_order is of the syntax:

field:dir

Whitelisting

Sometimes we want to allow filtering/querying only by specific model attributes or by specific related models.

To enable whitelisting on a model add the interface FilterWhitelistable and trait FilterWhitelist to it. If a model doesn't have this interface, whitelisting is not enabled on it and filtering can happen on any attribute/relationship.

Define all whitelisted attributes in a filterableAttributes array in the model.

Define all whitelisted relationships in a filterableRelations array in the model.

Example:

Simple syntax

filters=base_filter1;base_filter2;...

gets transformed to

filters[AND]=base_filter1;base_filter2;...

Configuration

Whitelisting can be globally enabled (default) and disabled. Add to .env

or publish the config file:

Example queries

Example queries on a sample posts endpoint.

License

Mozilla Public License 2.0, see LICENSE for more information.

Copyright @2025 Cognitas d.o.o.


All versions of query-filter with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
illuminate/database Version 11.*|12.*
illuminate/support Version 11.*|12.*
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package cognitas/query-filter contains the following files

Loading the files please wait ...