Download the PHP package mehdirajabi/filterable without Composer
On this page you can find all versions of the php package mehdirajabi/filterable. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mehdirajabi/filterable
More information about mehdirajabi/filterable
Files in mehdirajabi/filterable
Package filterable
Short Description Filter eloquent model by array query strings
License MIT
Informations about the package filterable
Filter Eloquent Models by Array Query Strings
Introduction
The Laravel Filterable Trait is a powerful package providing a reusable trait for easily implementing filter functionality in your Laravel Eloquent models. It enables filtering query results based on multiple parameters, making it simpler to create dynamic and flexible APIs or data filtering mechanisms in your applications.
Features
- Easily implement filtering on Eloquent models.
- Filter data based on various query parameters.
- Support for multiple filter types, such as exact matches, partial matches, ranges, etc.
- Customizable and extensible for adding new filter types.
- Improves code readability and maintainability by separating filtering logic from the main model.
Installation
You can install the package via Composer by running the following command:
Usage
1. Apply the Filterable Trait to Your Eloquent Model
Open the Eloquent model where you want to apply the filtering functionality and add the Filterable trait:
In your controller:
2. How Does Filterable Work?
Two query strings, filterColumns and filterValues, are used, both being arrays. The default operator for all columns is the "like" operator.
For example:
3. Relational Filter
To filter on a relation, add the column name as nested. For example, if a user has a relation with a profile and the profile has a 'sex' column, use the following convention:
4. Change Filter Mode Operator
To change the operator of the 'status' column, define the filterMode property: