Download the PHP package aldemeery/sieve without Composer

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

Sieve - Clean & Easy Eloquent Filtration

Build Status Total Downloads Latest Stable Version License

This package allows you to filter retrieved records based on query string values.

Once installed filtration shrinks down from this:

to this:

Installation

This package can be used in Laravel 5.8 or higher. You can install the package via composer:

The service provider will automatically get registered. Or you may manually add the service provider in your config/app.php file:

Usage

Enabling filtration for a model is as easy as adding the Aldemeery\Sieve\Concerns\Filterable trait to your model(s):

The Filterable trait adds a filter local scope to your model which accepts an instance of Illuminate\Htpp\Request so it can be used for filtration like this:

Once you have added the trait to your model, and used the filter method , you just need to start creating filters.

Creating filters

A filter class is a class that extends Aldemeery\Sieve\Filter.

You can manually create a filter class and place wherever you like, or use the make:filter artisan command to create a filter which will be placed inside app/Http/Filters directory.

This will typically create the following class:

The filter method inside a filter class, is where you should put your filtration logic. The $value parameter is holding the value passed in the query string for this specific filter key.

Note: the key 'color' in the above example is defined when you actually use the filter

Because you have an instance of Illuminate\Database\Eloquent\Builder, you have all of its power, which means you can do all different sorts of things:

Mappings

Sometimes you might want to use more meaningful values for your query string keys, however these values could be different from the values you actually need for filtration, this is where the $mappings comes to help.

You can define your values mappings in the $mappings array , and they will be automatically resolved before being passed to the filter method, keep reading...

Example: Let's assume you would like to order a list of products by their price, and you don't want to have: ..?price=asc or ..?price=desc in your URL, instead you would like to have something like: ..?price=lowest or ..?price=highest

to achieve this you have the following filter class:

Using "individual" filters

Once you have created your filter and defined your filtration logic, It's time now to actually use the filter, which can be done in three ways:

Passing a filters array to filter:

Use this when you want to apply a filter to a single query:

In the above example the filter will look for the value of the key color in the query string for this query only, and pass it to the filter method inside the filter class where you have put your filtration logic.

Defining model filters:

The Filterable trait providers a filters method that should return an array of "keys" and "filters" to be applied to the model every time the filter method is called.

Now everytime you call the filter method on the model, you will have the ColorFilter applied on your query without passing any external arguments.

Filter Bags

Sometimes you might have a large list of filters that is making your model look messy, or you might want to group a list of filters so you can share them between different models. This is when you want to have a filter bag.

A filter bag is a class that extends Aldemeery\Sieve\FilterBag and contains an array of filters that are always applied together.

Again you can manually create your filter bag class and place it wherever you like, or use the make:filter-bag command to create a filter bag class that is placed inside the app\Http\Filters directory.

This will typically create the following class:

Again, put your "key" and "filter" pairs inside the $filters array:

And once you have done that, you just need to override the filterBag method from the Filterable trait inside your model, to return which filter bag should be used.

Now everytime the filter method is called on the model, all the filters inside the ProductFilters will be applied.

License

The MIT License (MIT). Please see License File for more information.


All versions of sieve with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
illuminate/support Version ^11.0
illuminate/database Version ^11.0
illuminate/console Version ^11.0
aldemeery/onion Version ^1.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 aldemeery/sieve contains the following files

Loading the files please wait ....