Download the PHP package mnabialek/laravel-eloquent-filter without Composer

On this page you can find all versions of the php package mnabialek/laravel-eloquent-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 laravel-eloquent-filter

Laravel Eloquent Filter

Build Status Coverage Status Scrutinizer Code Quality StyleCI Packagist

This module lets you filter Eloquent data using query filters. You can apply WHERE filters and also set order of results

Installation

  1. Run

    in console to install this module

  2. That's it! Installation is complete. You don't need to adjust any config or install service providers.

Getting started

Let's assume you want to allow to filter users data. By default you use User Eloquent model to get users. To enable filtering, open User model (by default app/User.php file) and add into it the following trait:

just bellow opening class definition, so it should look something like this:

To allow filtering for this class, you need to also create implementation of Mnabialek\LaravelEloquentFilter\Contracts\QueryFilter interface. To do that create min app/Filters directory file with the following content:

As you see, you don't implement here the whole contract but you only extend SimpleQueryFilter class that does it for you.

Now you need to go to place where you get users data. Let's assume in your controller you get your users using:

All you need to do now, is changing it into:

Obviously you can use method dependency injection for that instead of using App::make here but it's only simple example that should work in all places of your app.

Now, let's assume you display your users using http://localhost/users url.

After those changes running:

Simple query parser and simple query filter

Although you can create custom parsers and filters, some default ones are provided.

By default you can pass to your url conditions using field with value for example id=5 and you can apply sorting using sort parameter with names of fields separated by comma. If you precede field by - sign, it will assume you want to sort by this field in descending order.

When implementing your filter class when you extend SimpleQueryParser in $simpleFilters and $simpleSorts you can specify any fields that might be filtered and sorted without any custom implementation. For those fields simple = comparison will be used and in case of array usage (for example id[]=2&id[]=5 it will be assumed you want to get data with logical OR operator.

However in real life you might want to specify custom filter or sort method. To do that, you need to implement your custom method for such field for example:

For created_at filter you can use

For id sort you can use for example:

You can also implement default filters and default sorting implementing applyDefaultFilters and applyDefaultSorts methods where you can check whether any filters or sorts were already applied.

Customization

Although this module provides some default implementations, you can create your own. You can change they way data is passed to QueryFilter. By default SimpleQueryParser is used that parses Request input in very basic way. However you might want to create your own implementation of Mnabialek\LaravelEloquentFilter\Contracts\InputParser to fully adjust it to your needs.

You might also change they way filters and sorts are applied to query. To do this, you need to create your own implementation of Mnabialek\LaravelEloquentFilter\Contracts\QueryFilter but again default implementation was given.

In case you want to only create implementation of QueryFilter, it might be convenient to create custom filter class, that will pass this specific QueryFilter implementation to QueryFilter instead of creating your own constructor in multiple filters classes. You can look at SimpleQueryFilter which does it for SimpleQueryParser to remove need of defining this constructor over and over in multiple filter classes (assuming you want to use SimpleQueryParser for them).

Licence

This package is licenced under the MIT license


All versions of laravel-eloquent-filter with dependencies

PHP Build Version
Package Version
Requires laravel/framework Version 5.*|6.*|7.*|8.*
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 mnabialek/laravel-eloquent-filter contains the following files

Loading the files please wait ....