{"id":37003465,"url":"https://github.com/esign/laravel-query-filters","last_synced_at":"2026-01-14T00:33:34.865Z","repository":{"id":57698403,"uuid":"495843052","full_name":"esign/laravel-query-filters","owner":"esign","description":null,"archived":false,"fork":false,"pushed_at":"2025-11-20T21:38:09.000Z","size":40,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-11-27T14:56:46.774Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/esign.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-05-24T13:47:39.000Z","updated_at":"2025-11-20T21:38:11.000Z","dependencies_parsed_at":"2023-10-17T03:03:36.260Z","dependency_job_id":"d893d42f-4a52-40ff-94ab-789f292c644e","html_url":"https://github.com/esign/laravel-query-filters","commit_stats":{"total_commits":11,"total_committers":3,"mean_commits":"3.6666666666666665","dds":0.2727272727272727,"last_synced_commit":"6e115027ae9189b85c11284f6c16b0be98195eed"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/esign/laravel-query-filters","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/esign%2Flaravel-query-filters","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/esign%2Flaravel-query-filters/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/esign%2Flaravel-query-filters/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/esign%2Flaravel-query-filters/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/esign","download_url":"https://codeload.github.com/esign/laravel-query-filters/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/esign%2Flaravel-query-filters/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28406509,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-13T21:51:37.118Z","status":"ssl_error","status_checked_at":"2026-01-13T21:45:14.585Z","response_time":56,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5: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":[],"created_at":"2026-01-14T00:33:34.119Z","updated_at":"2026-01-14T00:33:34.858Z","avatar_url":"https://github.com/esign.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Apply filters to Laravel's query builder.\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/esign/laravel-query-filters.svg?style=flat-square)](https://packagist.org/packages/esign/laravel-query-filters)\n[![Total Downloads](https://img.shields.io/packagist/dt/esign/laravel-query-filters.svg?style=flat-square)](https://packagist.org/packages/esign/laravel-query-filters)\n![GitHub Actions](https://github.com/esign/laravel-query-filters/actions/workflows/main.yml/badge.svg)\n\nThis package allows you to easily apply filters to Laravel's query builder by abstracting filter logic into dedicated classes.\n\n## Installation\n\nYou can install the package via composer:\n\n```bash\ncomposer require esign/laravel-query-filters\n```\n\nThe package will automatically register a service provider.\n\n## Usage\n\n### Preparing your model\nTo apply filters to your model you may use the `Esign\\QueryFilters\\Concerns\\Filterable` trait:\n```php\nuse Esign\\QueryFilters\\Concerns\\Filterable;\nuse Illuminate\\Database\\Eloquent\\Model;\n\nclass Post extends Model\n{\n    use Filterable;\n}\n```\n\n### Applying filters\nAfter applying the trait to your model, a query scope `filter` will be available, that accepts an array of possible filters:\n```php\nuse App\\Models\\Filters\\TitleFilter;\nuse App\\Models\\Filters\\BodyFilter;\n\nPost::filter([\n    TitleFilter::class,\n    BodyFilter::class,\n])-\u003eget();\n```\n\nThe `filter` scope will send the query builder through an array of filters.\nTo pass the query builder to the next filter, you should call the `$next` callback with the `$query`.\n\nYou're not limited to only using string based classes as filters, you can pass actual instances, callbacks, or pass parameters along with your class based string:\n```php\nuse App\\Models\\Filters\\TitleFilter;\nuse Closure;\nuse Illuminate\\Database\\Eloquent\\Builder;\n\nPost::filter([\n    // Class strings\n    TitleFilter::class,\n    // Class strings that pass a parameter to the handle method\n    TitleFilter::class . ':dogs',\n    // Class instance with a constructor parameter\n    new TitleFilter('dogs'),\n    // Use a callback\n    function (Builder $query, Closure $next): Builder {\n        $query-\u003ewhere('title', 'like', '%dogs%');\n\n        return $next($query);\n    },\n])-\u003eget();\n```\n\n### Defining default filters\nIn case you do not provide an array of filter items, you may define a set of default filters on your model:\n```php\nuse App\\Models\\Filters\\TitleFilter;\nuse Esign\\QueryFilters\\Concerns\\Filterable;\nuse Illuminate\\Database\\Eloquent\\Model;\n\nclass Post extends Model\n{\n    use Filterable;\n\n    public function getFilters(): array\n    {\n        return [\n            TitleFilter::class,\n        ];\n    }\n}\n```\n\nYou may now call the `filter` scope without passing an array:\n```php\nPost::filter()-\u003eget();\n```\n\n### Creating filters\nTo create a filter class you may use the `make:filter` Artisan command:\n```bash\nphp artisan make:filter TitleFilter\n```\n\n```php\nnamespace App\\Models\\Filters;\n\nuse Closure;\nuse Illuminate\\Database\\Eloquent\\Builder;\nuse Illuminate\\Http\\Request;\n\nclass TitleFilter\n{\n    public function __construct(protected Request $request)\n    {}\n\n    public function handle(Builder $query, Closure $next): Builder\n    {\n        $query-\u003ewhere('title', 'like', '%' . $this-\u003erequest-\u003equery('search') . '%');\n\n        return $next($query);\n    }\n}\n```\n\n### Method filters\nThis package also ships with a handy `MethodFilter` class that allows you to define filters for query string parameters as methods.\nImagine we have a request that filters a list of posts with the following query string: `?published_at=2022-01-01\u0026title=dogs`.\nWe could create a `PostFilter` that extends the `MethodFilter` class with the camelcased method names:\n\n```php\nuse Esign\\QueryFilters\\Filters\\MethodFilter;\nuse Illuminate\\Database\\Eloquent\\Builder;\n\nclass PostFilter extends MethodFilter\n{\n    public function title(mixed $value): Builder\n    {\n        return $this-\u003equery-\u003ewhere('title', 'like', \"%$value%\");\n    }\n\n    public function publishedAt(mixed $value): Builder\n    {\n        return $this-\u003equery-\u003ewhere('published_at', '=', $value);\n    }\n}\n```\n\nBy default, query string parameters that contain an empty value won't be called.\n\n### Testing\n\n```bash\ncomposer test\n```\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fesign%2Flaravel-query-filters","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fesign%2Flaravel-query-filters","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fesign%2Flaravel-query-filters/lists"}