jurager/filterable

Laravel package for building complex eloquent filters in a simple, structured way

Maintainers

Package info

github.com/Jurager/filterable

pkg:composer/jurager/filterable

Statistics

Installs: 3

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

dev-main 2026-06-25 10:55 UTC

This package is auto-updated.

Last update: 2026-06-25 10:55:12 UTC


README

Latest Stable Version Total Downloads PHP Version Require License

A Laravel package that adds JSON:API-compatible filter and sort query parameter support to Eloquent models.

Features:

  • Declarative $filterable and $sortable arrays 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 whereHas subqueries 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/eav resolver
  • NestedSet descendant expansion via the tree operator

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.