Download the PHP package kalimeromk/filterable without Composer
On this page you can find all versions of the php package kalimeromk/filterable. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download kalimeromk/filterable
More information about kalimeromk/filterable
Files in kalimeromk/filterable
Package filterable
Short Description A Laravel package that simplifies dynamic filtering and searching across models and their relationships, eliminating repetitive query code.
License MIT
Informations about the package filterable
Filterable - Laravel Package for Dynamic Filtering
Filterable is a Laravel package designed to simplify dynamic filtering and searching across models and their relationships, eliminating the need for repetitive query code. It provides an easy-to-use trait and a query macro for building powerful, dynamic query filters.
Requirements
- PHP 8.1 – 8.5
- Laravel 10, 11, 12 or 13
Installation
Require the package via Composer:
The package uses package auto-discovery, so no manual registration is needed. If auto-discovery is disabled, register the service provider yourself:
Usage
1. The whereLike macro
whereLike performs a LIKE search over several columns at once, including columns on related models. All conditions
are grouped and combined with OR, so it can be chained with other constraints safely.
Searching related models
Use dot notation. Everything before the last dot is treated as the relation, so nested relations work too:
A single attribute may be passed as a plain string: ->whereLike('email', 'john@').
2. The Filterable trait
The trait adds a filter() scope that turns a request payload into query constraints.
How each filter key is resolved
| Filter key | Condition applied | Requirement |
|---|---|---|
is_active |
where('users.is_active', (bool) $value) |
listed in $boolFields |
name |
where('users.name', 'LIKE', '%value%') |
in $fillable and $likeFields |
email |
exact match | in $fillable |
['a', 'b'] |
whereIn |
in $fillable |
age_min |
where('users.age', '>=', $value) |
age in $fillable |
age_max |
where('users.age', '<=', $value) |
age in $fillable |
Keys that don't resolve to a fillable column are ignored, which keeps arbitrary request input from reaching the query.
null values are skipped, so absent query parameters don't narrow the result set.
[!IMPORTANT] For
age_min/age_maxit is the base column (age) that must be in$fillable— notage_minitself.
$likeFields applies to this model's own columns. To search related models, use the whereLike macro.
Example controller
Request:
Returns active users whose name contains "Jane" and whose age is between 25 and 35.
Testing
The package is tested with Orchestra Testbench:
License
This package is open-sourced software licensed under the MIT license.
All versions of filterable with dependencies
illuminate/database Version ^10.0|^11.0|^12.0|^13.0
illuminate/support Version ^10.0|^11.0|^12.0|^13.0