Download the PHP package ans-group/laravel-sieve without Composer

On this page you can find all versions of the php package ans-group/laravel-sieve. 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 laravel-sieve

UKFast Logo

Laravel Sieve

A library to handle filtering and sorting for your APIs

Filters like /pets?name:in=Snoopy,Hobbes will be applied to your query builder instance and only results matching that criteria will return

Installation

First, use composer to require the package as below:

In Laravel the service provider will be automatically discovered.

If you are using Lumen you will need to register the service provider in the "Register Service Providers" section of bootstrap/app.php:

Usage

Sieve uses an expressive API to configure these filters:

Filters

Filters are done in the query parameters with the format property:operator=term, for example

By default, if no operator is specified, it will default to eq so name=Bob will expand to name:eq=Bob

Like & Not Like

The string filter also supports like and not like operators. To use these you should use * as the wildcard rather than % as you would in a typical database query.

For instance first_name:lk=Sam* would match Sam, Samuel and Samantha.

Sorting

You can set the fields that can be sortable when setting up your model.
You can pass an array of fields as the second parameter of configure.
It does not have to match the filterable, allowing total control.

Sieve will also allow consumers of your API to specify sort order. You can do this by sort=property:direction

If you do not specify a direction (for instance sort=age) then the sorting will be carried out in ascending order.

You can specify more than one column to sort by as a comma separated list. These will be applied in the order given. For instance sort=age:asc,name:asc will return people in age order, then alphabetically.

By default, MySQL will sort null values first for ascending sorts and last for descending sorts. Depending on the context of the column this may not be the desired functionality. You can change this using the following URL queries:

You can set a default sort using the setDefaultSort on theSieve class. The default sort uses the database column name rather than the mapped property name, meaning you can use the default sort property without having a map set up.

Available Filters

String

The basic filter. Ideal for textual data, implements eq, neq, in, nin, lk and nlk

Numeric

Ideal for numerical data, on top of the basic operators, it also provides lt (less than) and gt (greater than)

Enum

Same as the string filter but with extra validation. Will throw an exception if the user gives an invalid value

Boolean

Only provides eq and neq. Also takes two arguments to specify what your true and false values are in the DB

Date

Provides the same operations as numeric

You can get type hinting for these filters by specifying FilterBuilder when using the configure method

Relationships

You can filter on relationships using the for method on the filter builder

You can also use the for method if your API properties don't match column names in the database, for example

Wrapping Filters

You can easily wrap all the available filters to decorate their behaviour. A good example of this is if your API has some kind of computed property

A very simple example might be you have a price property that's stored in pence in the DB, but displayed as pounds in the API (not necessarily good practice, but works for the example)

We can still filter on this by setting up a wrapper that will modify the consumers query before passing it to the filter:

This can be used by doing the following:

Now when the user searches for price:eq=1.50 the database query will instead be WHERE price = 150

It's worth noting that wrap can be called multiple times and the builder will repeatedly re-wrap

Contributing

We welcome contributions to this package that will be beneficial to the community.

You can reach out to our open-source team via [email protected] who will get back to you as soon as possible.

Please refer to our CONTRIBUTING file for more information.

Security

If you think you have identified a security vulnerability, please contact our team via [email protected] who will get back to you as soon as possible, rather than using the issue tracker.

Licence

This project is licenced under the MIT Licence (MIT). Please see the Licence file for more information.


All versions of laravel-sieve with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
illuminate/database Version ^11.0
illuminate/http Version ^11.0
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 ans-group/laravel-sieve contains the following files

Loading the files please wait ....