jurager / filterable
Laravel package for building complex eloquent filters in a simple, structured way
dev-main
2026-06-25 10:55 UTC
Requires
- php: ^8.4
- illuminate/database: ^11.0|^12.0|^13.0
- illuminate/http: ^11.0|^12.0|^13.0
- illuminate/support: ^11.0|^12.0|^13.0
Requires (Dev)
- laravel/pint: ^1.0
- orchestra/testbench: ^9.0|^10.0
- phpunit/phpunit: ^11.0|^12.0
Suggests
- aimeos/laravel-nestedset: Required for tree (descendants) filtering
- jurager/eav: Provides entity-attribute-value attribute filtering
This package is auto-updated.
Last update: 2026-06-25 10:55:12 UTC
README
A Laravel package that adds JSON:API-compatible filter and sort query parameter support to Eloquent models.
Features:
- Declarative
$filterableand$sortablearrays on the model — no boilerplate controllers - Full operator set:
eq,ne,gt,gte,lt,lte,like,in,nin,null,not_null,between,not_between,tree - Relation filtering via
whereHassubqueries and pivot column support - Filtered eager-loading with
filter[included.*] - OR / AND condition groups
- Field, relation, and sort resolver interfaces for custom SQL
- Full-result caching (Redis / Memcached) with automatic tag-based invalidation
- Entity-Attribute-Value attribute filtering via
jurager/eavresolver - NestedSet descendant expansion via the
treeoperator
Requirements
- PHP 8.2+
- Laravel 11+
Installation
composer require jurager/filterable
Add HasFilterable to your model and declare allowed fields:
use Jurager\Filterable\Concerns\HasFilterable; class Product extends Model { use HasFilterable; protected array $filterable = [ 'sku' => ['eq', 'like'], 'price' => ['gte', 'lte', 'between'], 'status' => ['eq', 'in'], 'category.name' => ['eq', 'like'], 'is_active', ]; protected array $sortable = ['id', 'sku', 'price', 'created_at']; }
Apply in the controller:
Product::query()->filter()->sort()->paginate();
Request:
GET /products?filter[status][in][]=active&filter[price][gte]=100&sort=-created_at
Documentation
To learn more about filtering, sorting, relations, caching, and advanced usage please go to the Documentation.
License
This package is open-sourced software licensed under the MIT license.