PHPackages                             jerome/filterable - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. jerome/filterable

ActiveLibrary[Database &amp; ORM](/categories/database)

jerome/filterable
=================

Streamline dynamic Eloquent query filtering with seamless API request integration and advanced caching strategies.

2.1.2(2mo ago)19226.1k↑37.2%10[2 PRs](https://github.com/Thavarshan/filterable/pulls)MITPHPPHP ^8.3 | ^8.4 | ^8.5CI passing

Since Apr 10Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/Thavarshan/filterable)[ Packagist](https://packagist.org/packages/jerome/filterable)[ Docs](https://github.com/Thavarshan/filterable)[ Fund](https://www.buymeacoffee.com/thavarshan)[ GitHub Sponsors](https://github.com/thavarshan)[ RSS](/packages/jerome-filterable/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (30)Versions (25)Used By (0)

[![Filterable](./assets/Banner.jpg)](https://github.com/Thavarshan/filterable)

About Filterable
================

[](#about-filterable)

[![Latest Version on Packagist](https://camo.githubusercontent.com/404aaed3d9442c696878b08a9b06e484030306a15fe99beaf3fe456d458fe950/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a65726f6d652f66696c74657261626c652e737667)](https://packagist.org/packages/jerome/filterable)[![Tests](https://github.com/Thavarshan/filterable/actions/workflows/tests.yml/badge.svg?label=tests&branch=main)](https://github.com/Thavarshan/filterable/actions/workflows/tests.yml)[![Lint](https://github.com/Thavarshan/filterable/actions/workflows/lint.yml/badge.svg)](https://github.com/Thavarshan/filterable/actions/workflows/lint.yml)[![CodeQL](https://github.com/Thavarshan/filterable/actions/workflows/github-code-scanning/codeql/badge.svg)](https://github.com/Thavarshan/filterable/actions/workflows/github-code-scanning/codeql)[![PHPStan](https://camo.githubusercontent.com/b6d441ad4fe8332cb16c72aa27f22cc685181dfd74ae34964afc92c6c1146b3c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d6c6576656c2532306d61782d627269676874677265656e2e737667)](https://phpstan.org/)[![PHP Version](https://camo.githubusercontent.com/7322bc94f373d204765504d876dd627ef5637b735f905b25aeaa2b656de554e5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6a65726f6d652f66696c74657261626c652e737667)](https://packagist.org/packages/jerome/filterable)[![License](https://camo.githubusercontent.com/0089b0f87a2266ef012cdab44870ad84f486fcb78547d5e5715154daa5f517c5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6a65726f6d652f66696c74657261626c652e737667)](https://packagist.org/packages/jerome/filterable)[![Total Downloads](https://camo.githubusercontent.com/3e5355b53f7919b9ead415a085eddce91ddf6f16f17feb55d58c5970786213bd/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6a65726f6d652f66696c74657261626c652e737667)](https://packagist.org/packages/jerome/filterable)[![GitHub Stars](https://camo.githubusercontent.com/4c256e8b64abec36b44c969c9e8d3aa75a2420a1ad8ae14188b41183775e5bd9/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f5468617661727368616e2f66696c74657261626c652e7376673f7374796c653d736f6369616c266c6162656c3d5374617273)](https://github.com/Thavarshan/filterable/stargazers)

Filterable is a Laravel package for turning HTTP request parameters into rich, composable Eloquent query filters. The base `Filter` class exposes a stateful pipeline that you can extend, toggle, and compose with traits to add validation, caching, logging, rate limiting, memory management, and more. Everything is opt-in, so you enable only the behaviour you need while keeping type-safe, testable filters.

Requirements
------------

[](#requirements)

- PHP 8.3, 8.4, or 8.5
- Laravel 11.x, 12.x, or 13.x components (`illuminate/cache`, `illuminate/contracts`, `illuminate/database`, `illuminate/http`, `illuminate/support`)
- A configured cache store when you enable caching features
- A PSR-3 logger when you enable logging (optional)

Installation &amp; Setup
------------------------

[](#installation--setup)

```
composer require jerome/filterable
```

Package auto-discovery registers the `FilterableServiceProvider`, which contextual-binds the current `Request` into resolved filters and exposes the `make:filter` Artisan command. Publish the configuration to set global feature defaults, cache behaviour, or runtime options:

```
php artisan vendor:publish --tag=filterable-config
```

Stubs live under `src/Filterable/Console/stubs/` and can be overridden by placing copies in your application's `stubs` directory.

Highlights
----------

[](#highlights)

- Publishable configuration (`config/filterable.php`) to set default feature bundles, runtime options, and cache TTLs that the base filter reads during construction.
- Stateful lifecycle with `apply`, `get`, `runQuery`, `reset`, rich debug output via `getDebugInfo()`, lifecycle events (`FilterApplying`, `FilterApplied`, `FilterFailed`), and configurable exception handling.
- Opt-in concerns for validation, permissions, rate limiting, caching (with heuristics), logging, performance metrics, query optimisation, memory management, value transformation, and fluent filter chaining.
- Drop-in `Filterable` Eloquent scope trait so any model can accept a filter instance.
- Smart caching that builds deterministic cache keys, supports tags, memoises counts, and can decide automatically when to cache complex queries.
- Contextual binding in `FilterableServiceProvider` makes sure container-resolved filters receive the current HTTP `Request`; injecting a cache repository or PSR-3 logger auto-enables the relevant features.
- Memory-friendly helpers (`lazy`, `stream`, `streamGenerator`, `lazyEach`, `cursor`, `chunk`, `map`, `filter`, `reduce`) when the `memoryManagement` feature is enabled.
- First-party Artisan generator with `--basic`, `--model`, and `--force` options to rapidly scaffold filters.

Repository Layout
-----------------

[](#repository-layout)

- `src/Filterable/Filter.php` – abstract base class orchestrating the filter lifecycle and feature toggles.
- `src/Filterable/Concerns/` – traits implementing discrete behaviour (filter discovery, validation, caching, logging, performance, optimisation, rate limiting, etc.).
- `src/Filterable/Contracts/` – interfaces for the filter pipeline and the Eloquent scope signature.
- `src/Filterable/Traits/Filterable.php` – model scope that forwards to a `Filter` instance.
- `src/Filterable/Console/MakeFilterCommand.php` &amp; `src/Filterable/Console/stubs/` – Artisan generator and overrideable stub templates.
- `src/Filterable/Providers/FilterableServiceProvider.php` – registers the package and console command via `spatie/laravel-package-tools`.
- `bin/` – executable scripts executed by the Composer `lint`, `fix`, and `test` commands.
- `tests/` – Orchestra Testbench suite with concern-focused tests and reusable fixtures in `tests/Fixtures/`.
- `assets/` – shared media used in documentation.
- `config/filterable.php` – publishable defaults for feature toggles, cache TTL, and runtime options.
- `database/factories/` – reserved for additional factories should you extend the package.

Quick Start
-----------

[](#quick-start)

### 1. Generate a filter

[](#1-generate-a-filter)

```
php artisan make:filter PostFilter --model=Post
```

`--model` wires the stub to your Eloquent model. Use `--basic` for an empty shell or `--force` to overwrite an existing class.

### 2. Implement filtering logic

[](#2-implement-filtering-logic)

```
