Download the PHP package emargareten/eloquent-filters without Composer

On this page you can find all versions of the php package emargareten/eloquent-filters. 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 eloquent-filters

Eloquent Filters

Latest Version on Packagist Tests Total Downloads

Eloquent Filterable is a package that helps you filter Laravel Eloquent models using arrays. With this package, you can easily filter Eloquent models based on different criteria and combinations of criteria.

Requirements

This package requires PHP 8.1 or later.

Installation

You can install the package via composer:

Usage

To get started, you need to add the Emargareten\EloquentFilterable\Filterable trait to your model. This trait adds a filter method to your model that you can use to filter your model.

Then, add a filterTypes property to your model that contains an array of filterable fields. The keys of the array are the names of the fields that can be filtered, and the values are the names of the filter-type that should be applied to the field.

Filter Types

The following filter types are available by default: string, number, boolean, date and time.

Each type has a corresponding filter class that is used to filter the field. For example, the string type uses the Emargareten\EloquentFilterable\Filters\StringFilter class.

To create your own filter types or override/extend existing types you should create a class where each method is a filter operator, the method name should be the operator name (camel case) and the method should accept 3 parameters: $query, $property and $value.

Then register your filter class in the filter_types config option. (Publish the file with php artisan vendor:publish --provider="Emargareten\EloquentFilterable\EloquentFilterableServiceProvider")

Filtering

You can filter your model by calling the filter method on your model and passing an array of filters.

Each filter consists of 3 elements property, operator and value.

The property is the name of the field that should be filtered, this field has to be defined in the filterTypes property of your model (this prevents SQL injection). The operator is the operator that should be used to filter the field (it can be in whatever casing you want). The value is the value that should be used to filter the field.

You can override the default operator type by prefixing the operator with the type and a colon (:). For example, if you want to use the string type for the age field instead of the number type, you can use the string:starts-with operator.

If you have only one filter, you can pass the filter directly to the filter method instead of an array of filters.

To group filters using OR you can nest the filters in an additional array.

The above example will return all users named John that are either younger than 18 or older than 60.

Filtering by a relationships

To filter by a relationship you can use the dot notation to specify the relationship and the field that should be filtered.

The above example will return all users that have a post with a title that contains the word laravel.

Note You have to use the Filterable trait on the related model in order to filter by relationship.

Available Operators

String Operators

Number Operators

Boolean Operators

Date Operators

Time Operators

Dynamic Custom Filters

You can define dynamic filters by adding a method to your model prefixed with filter (similar to the scope prefix for local scopes).

You can also define a dynamic filter that accepts an operator and a value:

You can then use the dynamic filter in your filter array:

Changelog

Please see CHANGELOG for more information about what has changed recently.

Testing

Contributing

Contributions are welcome! If you find any bugs or issues or have a feature request, please open a new issue or submit a pull request. Before contributing, please make sure to read the Contributing Guide.

License

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


All versions of eloquent-filters with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
illuminate/support Version ^9.0|^10.0|^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 emargareten/eloquent-filters contains the following files

Loading the files please wait ....