{"id":21069051,"url":"https://github.com/kettasoft/filterable","last_synced_at":"2026-04-02T01:18:41.308Z","repository":{"id":174410634,"uuid":"652194733","full_name":"kettasoft/filterable","owner":"kettasoft","description":"A powerful and flexible Laravel package for advanced, clean, and scalable filtering of Eloquent models using multiple customizable engines.","archived":false,"fork":false,"pushed_at":"2026-03-19T01:38:19.000Z","size":7003,"stargazers_count":10,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-03-19T15:38:38.023Z","etag":null,"topics":["eloquent","engines","filter","filter-design","filterable","filtering","filtering-data","filters","filtersystem","laravel","model","php","query-builder","search","search-engine","searchable","searching"],"latest_commit_sha":null,"homepage":"https://kettasoft.github.io/filterable/","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kettasoft.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2023-06-11T11:50:02.000Z","updated_at":"2026-03-19T01:37:42.000Z","dependencies_parsed_at":"2025-01-20T21:37:38.104Z","dependency_job_id":"0047be90-700f-4b27-9579-ed10f67b556a","html_url":"https://github.com/kettasoft/filterable","commit_stats":null,"previous_names":["kettasoft/laravel-eloquent-filter","kettasoft/filterable"],"tags_count":29,"template":false,"template_full_name":null,"purl":"pkg:github/kettasoft/filterable","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kettasoft%2Ffilterable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kettasoft%2Ffilterable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kettasoft%2Ffilterable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kettasoft%2Ffilterable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kettasoft","download_url":"https://codeload.github.com/kettasoft/filterable/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kettasoft%2Ffilterable/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31293764,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-02T01:05:07.454Z","status":"ssl_error","status_checked_at":"2026-04-02T00:56:46.496Z","response_time":53,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["eloquent","engines","filter","filter-design","filterable","filtering","filtering-data","filters","filtersystem","laravel","model","php","query-builder","search","search-engine","searchable","searching"],"created_at":"2024-11-19T18:31:07.843Z","updated_at":"2026-04-02T01:18:41.302Z","avatar_url":"https://github.com/kettasoft.png","language":"PHP","readme":"\u003cp align=\"center\"\u003e\u003cimg src=\"https://github.com/kettasoft/filterable/blob/docs/images/logo.png\" width=\"180\" alt=\"Filterable Logo\" /\u003e\u003c/p\u003e\n\u003ch1 align=\"center\"\u003eFilterable\u003c/h1\u003e\n\u003cp align=\"center\"\u003eA powerful and flexible Laravel package for advanced, clean, and scalable filtering of Eloquent models using multiple customizable engines.\u003c/p\u003e\u003cp align=\"center\"\u003e\n\u003ca href=\"https://packagist.org/packages/kettasoft/filterable\"\u003e\u003cimg src=\"https://github.com/kettasoft/filterable/actions/workflows/php.yml/badge.svg?style=flat-square\" alt=\"Tests\"\u003e\u003c/a\u003e\n\u003ca href=\"https://packagist.org/packages/kettasoft/filterable\"\u003e\u003cimg src=\"http://poser.pugx.org/kettasoft/filterable/v?style=flat-square\" alt=\"Latest Version on Packagist\"\u003e\u003c/a\u003e\n\u003ca href=\"https://packagist.org/packages/kettasoft/filterable\"\u003e\u003cimg src=\"https://img.shields.io/packagist/dt/kettasoft/filterable?style=flat-square\" alt=\"Total Downloads\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/kettasoft/filterable/blob/master/LICENSE\"\u003e\u003cimg src=\"https://poser.pugx.org/kettasoft/filterable/license?style=flat-square\" alt=\"License\"\u003e\u003c/a\u003e\u003c/p\u003e\n\n## Why Filterable?\n\nMost filtering packages give you one approach and expect you to fit your problem around it. Filterable works the other way — you pick the **engine** that matches how your frontend sends data, and the package handles the rest.\n\nIt ships with four production-ready engines, a full caching system, per-filter authorization, validation, sanitization, sorting, a CLI, and an event system — all while keeping your controllers clean and your filter logic organized and testable.\n\n---\n\n## Installation\n\n```bash\ncomposer require kettasoft/filterable\n```\n\n```bash\nphp artisan vendor:publish --provider=\"Kettasoft\\Filterable\\Providers\\FilterableServiceProvider\" --tag=\"config\"\n```\n\nAdd the following line to the providers array in config/app.php or bootstrap/providers.php:\n\n```php\n'providers' =\u003e [\n    ...\n\n    Kettasoft\\Filterable\\Providers\\FilterableServiceProvider::class,\n];\n```\n\n---\n\n## Quick Start\n\n**1. Create a filter class**\n\n```bash\nphp artisan filterable:make-filter PostFilter --filters=title,status\n```\n\n**2. Define your filters**\n\n```php\nnamespace App\\Http\\Filters;\n\nuse Kettasoft\\Filterable\\Filterable;\nuse Kettasoft\\Filterable\\Support\\Payload;\n\nclass PostFilter extends Filterable\n{\n    protected $filters = ['status', 'title'];\n\n    protected function title(Payload $payload)\n    {\n        return $this-\u003ebuilder-\u003ewhere('title', 'like', $payload-\u003easLike('both'));\n    }\n\n    protected function status(Payload $payload)\n    {\n        return $this-\u003ebuilder-\u003ewhere('status', $payload-\u003evalue);\n    }\n}\n```\n\n**3. Apply in your controller**\n\n```php\n$posts = Post::filter(PostFilter::class)-\u003epaginate();\n```\n\n**4. Or bind the filter directly to the model**\n\n```php\nclass Post extends Model\n{\n    use HasFilterable;\n\n    protected $filterable = PostFilter::class;\n}\n\n// Now just:\n$posts = Post::filter()-\u003epaginate();\n```\n\n---\n\n## Choosing an Engine\n\nEach engine is designed for a different filtering style. Pick the one that fits your use case — or mix and match across different models.\n\n| Engine         | Best For                                           | Example Request                                       |\n| -------------- | -------------------------------------------------- | ----------------------------------------------------- |\n| **Invokable**  | Custom logic per field, method-per-filter pattern  | `?status=active\u0026title=laravel`                        |\n| **Ruleset**    | Clean key/operator/value API queries               | `?filter[title][like]=laravel\u0026filter[views][gte]=100` |\n| **Expression** | Ruleset-style + filtering through nested relations | `?filter[author.profile.name][like]=ahmed`            |\n| **Tree**       | Complex AND/OR nested logic sent as JSON           | `{ \"and\": [{ \"field\": \"status\", ... }] }`             |\n\n### Invokable Engine\n\nMap request keys to methods automatically. Add PHP 8 annotations for per-method sanitization, casting, validation, and authorization with zero boilerplate.\n\n```php\nclass PostFilter extends Filterable\n{\n    protected $filters = ['status', 'created_at'];\n\n    #[Cast('integer')]\n    #[DefaultValue(1)]\n    protected function status(Payload $payload) { ... }\n\n    #[SkipIf('auth()-\u003eguest()')]\n    #[Between(min: '2020-01-01', max: 'now')]\n    protected function created_at(Payload $payload) { ... }\n}\n```\n\nAvailable annotations: `#[Authorize]` `#[SkipIf]` `#[Cast]` `#[Sanitize]` `#[Trim]` `#[DefaultValue]` `#[MapValue]` `#[Explode]` `#[Required]` `#[In]` `#[Between]` `#[Regex]` `#[Scope]`\n\n### Ruleset Engine\n\nFlat field-operator-value format, ideal for REST APIs where the frontend controls which operator to use.\n\n```\nGET /posts?filter[status]=published\nGET /posts?filter[title][like]=%laravel%\nGET /posts?filter[views][gte]=100\nGET /posts?filter[id][in][]=1\u0026filter[id][in][]=2\n```\n\nSupported operators: `eq` `neq` `gt` `gte` `lt` `lte` `like` `nlike` `in` `between`\n\n### Expression Engine\n\nEverything Ruleset does, plus filtering through deep Eloquent relationships using dot notation.\n\n```\nGET /posts?filter[author.profile.name][like]=ahmed\n```\n\n```php\nFilterable::create()\n    -\u003euseEngine('expression')\n    -\u003eallowedFields(['status', 'title'])\n    -\u003eallowRelations(['author.profile' =\u003e ['name']])\n    -\u003epaginate();\n```\n\n### Tree Engine\n\nSend a nested AND/OR JSON tree — the engine recursively translates it into Eloquent `where` / `orWhere` groups.\n\n```json\n{\n    \"filter\": {\n        \"and\": [\n            { \"field\": \"status\", \"operator\": \"eq\", \"value\": \"active\" },\n            {\n                \"or\": [\n                    { \"field\": \"age\", \"operator\": \"gt\", \"value\": 25 },\n                    { \"field\": \"city\", \"operator\": \"eq\", \"value\": \"Cairo\" }\n                ]\n            }\n        ]\n    }\n}\n```\n\nSupports depth limiting, strict operator whitelisting, and normalized field keys.\n\n---\n\n## Features\n\n### Caching\n\nA complete caching system built into the filter pipeline — not bolted on after the fact.\n\n```php\n// Cache for 1 hour\nPost::filter()-\u003ecache(3600)-\u003eget();\n\n// User-scoped cache (each user gets their own)\nPost::filter()-\u003ecache(1800)-\u003escopeByUser()-\u003eget();\n\n// Tenant-isolated cache\nProduct::filter()-\u003ecache(3600)-\u003escopeByTenant(tenant()-\u003eid)-\u003eget();\n\n// Conditional cache\nModel::filter()-\u003ecacheWhen(!auth()-\u003euser()-\u003eisAdmin(), 3600)-\u003eget();\n\n// Tagged cache with easy invalidation\nPost::filter()-\u003ecache(3600)-\u003ecacheTags(['posts', 'content'])-\u003eget();\nPost::flushCacheByTagsStatic(['posts']);\n\n// Reusable profiles defined in config\nReport::filter()-\u003ecacheProfile('heavy_reports')-\u003eget();\n```\n\nAuto-invalidation: configure models and tags in `config/filterable.php` and caches are cleared automatically on create/update/delete.\n\n### Authorization\n\nProtect entire filter classes based on roles or permissions.\n\n```php\nclass AdminFilter extends Filterable\n{\n    public function authorize(): bool\n    {\n        return auth()-\u003euser()?-\u003eisSuperAdmin() ?? false;\n    }\n}\n```\n\nPer-method authorization is also available via the `#[Authorize]` annotation in the Invokable engine.\n\n### Validation \u0026 Sanitization\n\nValidation rules and sanitizers are defined directly on the filter class —\ninput is cleaned and validated before any filtering logic runs.\n\n**Validation** uses Laravel's native rules format via a `$rules` property:\n\n```php\nclass PostFilter extends Filterable\n{\n    protected $rules = [\n        'status' =\u003e ['required', 'string', 'in:active,pending,archived'],\n        'title'  =\u003e ['sometimes', 'string', 'max:32'],\n    ];\n}\n```\n\nIf validation fails, a `ValidationException` is thrown automatically —\nno extra handling needed in your controller.\n\n**Sanitization** runs _before_ validation, via dedicated sanitizer classes:\n\n```php\nclass PostFilter extends Filterable\n{\n    protected $sanitizers = [\n        TrimSanitizer::class,        // global — applies to all fields\n        'title' =\u003e [\n            StripTagsSanitizer::class,\n            CapitalizeSanitizer::class,\n        ],\n    ];\n}\n```\n\nA sanitizer is a simple class implementing the `Sanitizable` interface:\n\n```php\nclass TrimSanitizer implements Sanitizable\n{\n    public function sanitize(mixed $value): mixed\n    {\n        return is_string($value) ? trim($value) : $value;\n    }\n}\n```\n\nThe execution order is always: **sanitize → validate → filter**.\n\n### Sorting\n\nBuilt-in sorting support with allowed-field whitelisting.\n\n```php\nclass PostFilter extends Filterable\n{\n    protected $sortable = ['created_at', 'views', 'title'];\n}\n\n// GET /posts?sort=-created_at (descending)\n// GET /posts?sort=views       (ascending)\n```\n\n### Event System\n\nHook into the filter lifecycle to add logging, metrics, or custom behavior.\n\n```php\n// Fired before filters are applied\nEvent::listen(FilterApplying::class, fn($e) =\u003e Log::info('Filtering '.$e-\u003emodel));\n\n// Fired after filters are applied\nEvent::listen(FilterApplied::class, fn($e) =\u003e $metrics-\u003erecord($e));\n```\n\n### Profile Management \u0026 Profiler\n\nSave and reuse filter configurations, and inspect exactly what queries each filter generates.\n\n### Lifecycle Hooks\n\n`initially()` and `finally()` hooks let you modify the query builder before or after filtering runs.\n\n---\n\n## CLI\n\n```bash\n# Generate a new filter class with interactive setup\nphp artisan filterable:setup PostFilter\n\n# Discover and auto-register all filter classes in your app\nphp artisan filterable:discover\n\n# List all registered filters\nphp artisan filterable:list\n\n# Test a filter class with a sample data string (key=value pairs)\nphp artisan filterable:test {filter} --model=User --data=\"status=active,age=30\"\n\n# Inspect a filter class (engines, fields, rules, etc.)\nphp artisan filterable:inspect PostFilter\n```\n\n---\n\n## Requirements\n\n- PHP 8.1+\n- Laravel 10.x or higher\n- Redis or Memcached recommended for tagged caching\n\n---\n\n## 📚 Documentation\n\nFor full documentation, installation, and usage examples, visit: **[kettasoft.github.io/filterable](https://kettasoft.github.io/filterable)**\n\n- [Introduction](https://kettasoft.github.io/filterable/introduction.html)\n- [Engines Overview](https://kettasoft.github.io/filterable/engines/invokable/)\n- [Caching System](https://kettasoft.github.io/filterable/caching/overview.html)\n- [Authorization](https://kettasoft.github.io/filterable/authorization.html)\n- [CLI Reference](https://kettasoft.github.io/filterable/cli/setup.html)\n- [API Reference](https://kettasoft.github.io/filterable/api/filterable.html)\n\n---\n\n## Contributing\n\nFound a bug or want to add an engine? PRs are welcome — please open an issue first to discuss.\n\n## License\n\nMIT © 2024-present [Kettasoft](https://github.com/kettasoft)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkettasoft%2Ffilterable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkettasoft%2Ffilterable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkettasoft%2Ffilterable/lists"}