{"id":22614035,"url":"https://github.com/labrodev/laravel-filter-components","last_synced_at":"2026-02-26T04:23:04.696Z","repository":{"id":207955176,"uuid":"720498560","full_name":"labrodev/laravel-filter-components","owner":"labrodev","description":"This repo is Laravel package to extend filtering functionality in Laravel projects. If you have a list with items and you use spatie/laravel-query-builder to filter them, this package could be useful for you. ","archived":false,"fork":false,"pushed_at":"2024-12-17T10:48:58.000Z","size":24,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-25T07:23:47.475Z","etag":null,"topics":["crud","filters","laravel","laravel-components","laravel-framework","laravel-package","laravel-spatie","php"],"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/labrodev.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"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}},"created_at":"2023-11-18T17:09:33.000Z","updated_at":"2024-12-17T10:49:02.000Z","dependencies_parsed_at":"2023-11-24T10:31:30.774Z","dependency_job_id":"d9874698-af21-482c-874b-faab5256bde7","html_url":"https://github.com/labrodev/laravel-filter-components","commit_stats":null,"previous_names":["labrodev/laravel-filter-components"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/labrodev%2Flaravel-filter-components","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/labrodev%2Flaravel-filter-components/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/labrodev%2Flaravel-filter-components/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/labrodev%2Flaravel-filter-components/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/labrodev","download_url":"https://codeload.github.com/labrodev/laravel-filter-components/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248381758,"owners_count":21094525,"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":["crud","filters","laravel","laravel-components","laravel-framework","laravel-package","laravel-spatie","php"],"created_at":"2024-12-08T18:07:25.088Z","updated_at":"2026-02-26T04:23:04.672Z","avatar_url":"https://github.com/labrodev.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# labrodev/laravel-filter-components\n\n---\nThis repo is Laravel package to extend filtering functionality in Laravel projects. If you have a list with items and you use spatie/laravel-query-builder to filter them, this package could be useful for you. \n\nThis package based on [spatie/laravel-query-builder](https://github.com/spatie/laravel-query-builder) use case. We express our appreciation to Spatie for inspiring us, sharing valuable experiences, and providing exceptional Laravel packages that we not only extensively use but also wholeheartedly recommend. \n\n## QueryBuilder classes\n\nIn this package you may find some custom part of Query Builder to extend filtering logic.\n\n**DateRangeFilter**\n\nQueryBuilder class which implements a logic to filter by range of dates using WhereBetween. \n\n**IsNotNullFilter**\n\nQueryBuilder class which implements a logic to filter by whereNull or whereNotNull depend on the given input value. Could be used when we just need to filter by some flag behind which there is a logic (like: Have unpaid invoices - Yes/No).\n\n**WhereInFilter**\n\nQueryBuilder class which implements a logic to filter b whereIn using given array of values (good for multiple selects as filters). \n\n## View components\n\nAlso in this package you may find filter components that render filter component depends on type and logic.  \n\nYou may public vendor views from this package to implement your own styles for filter components blade templates and to adjust it to your layout and theme. \n\nBy default filter components in blade use Bootstrap classes. \n\n**Boolean filter**\n\nView component to render a filter with select options No,Yes (or custom options defined in component attribute).\n\n**Custom select filter**\n\nView component to render a filter with custom select options as filter options. \n\n**Date range filter**\n\nView component to render a filter with two date inputs as date range (start date and end date).\n\n**Input filter**\n\nView component to render a filter with text input.\n\n**Multiple select field**\n\nView component to render a filter with multiple select options from given Eloquent Model. \n\n**Select field**\n\nView component to render a filter with select options from given Eloquent Model. \n\n**Link**\n\nView component to render a sort field.\n\n## Installation\n\nYou can install the package via composer:\n\n```bash\ncomposer require labrodev/laravel-filter-components\n```\n\nOptionally, you can publish the views to implement them to your layout. \n\n```bash\nphp artisan vendor:publish --tag=filter-components-views\n```\n\nOptionally, you can publish the view components to extend the logic you need.\n\n```bash\nphp artisan vendor:publish --tag=filter-components-components\n```\n\n## Usage\n\n### QueryBuilder classes\n\nLet's assume that you are familiar with [Spatie\\QueryBuilder](https://spatie.be/docs/laravel-query-builder/v5/introduction) and already implemented filtering logic using Spatie\\QueryBuilder. \n\nYou may extend usage by using QueryBuilder classes from this package: DateRangeFilter, WhereInFilter, IsNotNullFilter.\n\n```php\nuse Illuminate\\Http\\Request;\nuse Labrodev\\Filters\\QueryBuilder\\DateRangeFilter;\nuse Labrodev\\Filters\\QueryBuilder\\WhereInFilter;\nuse Labrodev\\Filters\\QueryBuilder\\IsNotNullFilter;\nuse Spatie\\QueryBuilder\\AllowedFilter;\nuse Spatie\\QueryBuilder\\QueryBuilder;\n\nclass YourQuery extends QueryBuilder\n{\n    public function __construct(Request $request)\n    {\n        $query = YourModel::query();\n\n        parent::__construct($query, $request);\n\n        //DateRangeFilter\n        $this-\u003eallowedFilters([\n            AllowedFilter::custom('filter_name', new DateRangeFilter(), 'table_column') \n        ]);\n\n        //DateRangeFilter\n        $this-\u003eallowedFilters([\n            AllowedFilter::custom('filter_name', new WhereInFilter(), 'table_column') \n        ]);\n\n        //IsNotNullFilter\n        $this-\u003eallowedFilters([\n            AllowedFilter::custom('filter_name', new IsNotNullFilter(), 'table_column') \n        ]);\n    }\n}\n```\n\n### View components\n\nLet's consider that you want to have a filtering in your CRUD list.\n\nThere could be a filter block. Let's assume to may have a form for your filters. \n\n```blade\n\u003cform action=\"your filter routing\" method=\"GET\"\u003e\n\u003c!-- and here could be components from this package --\u003e\n\u003cbutton type=\"submit\"\u003e\u003c/button\u003e\n\u003c/form\u003e\n```\n\n**Boolean filter**\n\n```blade\n\u003cx-filter-boolean-field \n    field=\"filter[{{ $filterField }}]\" \n    name=\"{{ __('Filter label') }}\" \n    options=\"{{__('Your option 1') }},{{ __('Your option 2')}}\"\u003e\n\u003c/x-filter-boolean-field\u003e\n```\n\n* field - this property is query parameter which will be in search request\n* name - this is label for this filter\n* options - options which will be in select box; if it is not provided, then it will No, Yes options by default\n\n**Custom select filter**\n\n```blade\n\u003cx-filter-custom-select-field\u003e\n    field=\"filter[{{ $filterField }}]\"\n    name=\"{{ __('Filter label') }}\"\n    options=\"{{__('Your option 1') }},{{ __('Your option 2')}}\"\u003e\n\u003c/x-filter-custom-select-field\u003e\n```\n\n* field - this property is query parameter which will be in search request\n* name - this is label for this filter\n* options - options which will be in select box\n\n**Date range filter**\n\n```blade\n\u003cx-filter-date-range-field\u003e\n    field=\"filter[{{ $filterField }}]\"\n    name=\"{{ __('Filter label') }}\"\u003e\n\u003c/x-filter-date-range-field\u003e\n```\n\n* field - this property is query parameter which will be in search request\n* name - this is label for this filter\n\n**Input filter**\n\n```blade\n\u003cx-filter-field\u003e\n    field=\"filter[{{ $filterField }}]\"\n    name=\"{{ __('Filter label') }}\"\u003e\n\u003c/x-filter-field\u003e\n```\n\n* field - this property is query parameter which will be in search request\n* name - this is label for this filter\n\n**Multiple select filter**\n\n```blade\n\u003cx-filter-multiple-select-field \n    field=\"filter[{{$filterField}}]\"\n    name=\"{{ __('Filter label') }}\"\n    class=\"{{ $eloquentModelClass }}\"\n    value=\"{{ $eloquentModelProperty}}\"\u003e\n\u003c/x-filter-multiple-select-field\u003e\n```\n\n* field - this property is query parameter which will be in search request\n* name - this is label for this filter\n* class - Eloquent model class from where will be taken values for options. For example, if class is App\\Models\\UserGroup, then will be rendered all user groups from `user_groups` table as options \n* value - property which will be shown as options. For example, if value will be `name`, column `name` from `user_groups` table will be used for option; if you want to split two columns to have them as option, put in value them separeted by comma: 'column1,column2'\n\n**Select filter**\n\n```blade\n\u003cx-filter-select-field \n     field=\"filter[{{$filterField}}]\"\n    name=\"{{ __('Filter label') }}\"\n    class=\"{{ $eloquentModelClass }}\"\n    value=\"{{ $eloquentModelProperty}}\"\u003e\n\u003c/x-filter-select-field\u003e\n```    \n\n* field - this property is query parameter which will be in search request\n* name - this is label for this filter\n* class - Eloquent model class from where will be taken values for options. For example, if class is App\\Models\\UserGroup, then will be rendered all user groups from `user_groups` table as options \n* value - property which will be shown as options. For example, if value will be `name`, column `name` from `user_groups` table will be used for option; if you want to split two columns to have them as option, put in value them separeted by comma: 'column1,column2'\n\n**Link**\n\n```blade\n\u003cx-sort-link name=\"{{ $fieldToSort }}\"\u003e\n\u003c/x-sort-link\u003e\n```  \n\n* name - field to sort \n\n## Testing\n\n```bash\ncomposer test\n```\n\n## PhpStan check\n\n```bash\ncomposer analyse\n```\n\n## Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.\n\n## Credits\n\n- [Labro Dev](https://github.com/labrodev)\n\n- [Spatie](https://github.com/spatie)\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flabrodev%2Flaravel-filter-components","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flabrodev%2Flaravel-filter-components","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flabrodev%2Flaravel-filter-components/lists"}