{"id":22827481,"url":"https://github.com/lacodix/laravel-model-filter","last_synced_at":"2026-01-11T10:52:43.854Z","repository":{"id":65328972,"uuid":"589509464","full_name":"lacodix/laravel-model-filter","owner":"lacodix","description":"Offers an simple way to filter and search eloquent models by array parameters and query strings","archived":false,"fork":false,"pushed_at":"2025-04-29T12:24:37.000Z","size":337,"stargazers_count":174,"open_issues_count":1,"forks_count":13,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-05-08T18:53:02.327Z","etag":null,"topics":["eloquent","filter","laravel","laravel-package","model"],"latest_commit_sha":null,"homepage":"","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/lacodix.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","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},"funding":{"github":"lacodix"}},"created_at":"2023-01-16T09:39:25.000Z","updated_at":"2025-05-05T07:44:37.000Z","dependencies_parsed_at":null,"dependency_job_id":"fd5d9c7c-6362-47cc-b473-e1f9e60a0549","html_url":"https://github.com/lacodix/laravel-model-filter","commit_stats":{"total_commits":67,"total_committers":3,"mean_commits":"22.333333333333332","dds":0.02985074626865669,"last_synced_commit":"11940bbf5b0983a63ddf4f729621c64828f90f4f"},"previous_names":[],"tags_count":66,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lacodix%2Flaravel-model-filter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lacodix%2Flaravel-model-filter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lacodix%2Flaravel-model-filter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lacodix%2Flaravel-model-filter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lacodix","download_url":"https://codeload.github.com/lacodix/laravel-model-filter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254414499,"owners_count":22067272,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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","filter","laravel","laravel-package","model"],"created_at":"2024-12-12T18:10:58.315Z","updated_at":"2026-01-11T10:52:43.847Z","avatar_url":"https://github.com/lacodix.png","language":"PHP","funding_links":["https://github.com/sponsors/lacodix"],"categories":[],"sub_categories":[],"readme":"# laravel-model-filter\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/lacodix/laravel-model-filter.svg?style=flat-square)](https://packagist.org/packages/lacodix/laravel-model-filter)\n[![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/lacodix/laravel-model-filter/test.yaml?branch=master\u0026label=tests\u0026style=flat-square)](https://github.com/lacodix/laravel-model-filter/actions?query=workflow%3Atest+branch%3Amaster)\n[![GitHub Code Style Action Status](https://img.shields.io/github/actions/workflow/status/lacodix/laravel-model-filter/style.yaml?branch=master\u0026label=code%20style\u0026style=flat-square)](https://github.com/lacodix/laravel-model-filter/actions?query=workflow%3Astyle+branch%3Amaster)\n[![Total Downloads](https://img.shields.io/packagist/dt/lacodix/laravel-model-filter.svg?style=flat-square)](https://packagist.org/packages/lacodix/laravel-model-filter)\n\nThis package allows you to filter, search and sort models while fetching from database with ease.\nIt contains additional functionality to use query strings to filter, search and sort.\n\nOnce installed you can filter, search and sort Models.\nYou can create own filters based on our base filters, create individual filters, or use\none of the extended filters, that are ready to use with less or even without configuration like TrashedFilter.\n\nAdditionally you can use the visualisation functionality of filters.\n\n## Documentation\n\nYou can find the entire documentation for this package on [our documentation site](https://www.lacodix.de/docs/laravel-model-filter)\n\n## Installation\n\n```bash\ncomposer require lacodix/laravel-model-filter\n```\n\n## Basic Usage\n\n### Filter\n\nCreate your first filter\n\n```bash \nphp artisan make:filter CreatedAfterFilter --type=date --field=created_at\n```\n\n```php\n// Set the filter mode\n// App\\Models\\Filters\\CreatedAfterFilter\npublic FilterMode $mode = FilterMode::GREATER_OR_EQUAL;\n\n// Apply this filter and the HasFilters trait to a Model\n// App\\Models\\Post\nuse HasFilters;\nprotected array $filters = [\n    CreatedAfterFilter::class,\n];\n\n// Somwhere in a controller, select all posts created after 1st of January 2023\nPost::filter(['created_after_filter' =\u003e '2023-01-01'])-\u003eget();\n\n// Do the same via query string by calling\n// this url: https://.../posts?created_after_filter=2023-01-01\nPost::filterByQueryString()-\u003eget();\n```\n\n### Search\n\n```php\n// add searchable fields and the IsSearchable trait to Model:\n// App\\Models\\Post\nuse IsSearchable;\nprotected array $searchable = [\n    'title',\n    'content',\n];\n\n// Somewhere in controller, find all posts that contain \"test\" in title or content\nPost::search('test')-\u003eget();\n\n// Do the same via query string by calling\n// this url: https://.../posts?search=test\nPost::searchByQueryString()-\u003eget();\n```\n\n### Visualize\n\nAll filters have a blade template that can visualize the filter with one or multiple input fields.\nTo visualize all filters of a dedicated model you can use a blade component:\n\n```php\n\u003cx-lacodix-filter::model-filters :model=\"Post::class\" /\u003e\n```\n\n### Grouping\n\nSometimes you don't need all of the filters for all parts of a web application. Maybe there shall\nbe different filters be available to the backend as in the frontend, or different user types\nshall be able to use different filters.\n\nFor such cases this package offers filter grouping when adding filters to models\n\n```php\nprotected array $filters = [\n    'frontend' =\u003e [\n        HotFilter::class,\n    ],\n    'backend' =\u003e [\n        CreatedAfterFilter::class,\n        PublishedFilter::class,\n    ]\n];\n```\n\nThe groups can be used in the scopes\n\n```php\nPost::filterByQueryString('frontend')-\u003eget()\n```\nor\n```php \nPost::filter(['hot_filter' =\u003e 'hot'], 'frontend')-\u003eget();\nPost::filter(['created_after_filter' =\u003e '2023-01-01'], 'backend')-\u003eget();\n```\n\n## Testing\n\n```bash\ncomposer test\n```\n\n## Contributing\n\nPlease run the following commands and solve potential problems before committing\nand think about adding tests for new functionality.\n\n```bash\ncomposer rector:test\ncomposer insights\ncomposer csfixer:test\ncomposer phpstan:test\n```\n\n## Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.\n\n## Credits\n\n- [lacodix](https://github.com/lacodix)\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%2Flacodix%2Flaravel-model-filter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flacodix%2Flaravel-model-filter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flacodix%2Flaravel-model-filter/lists"}