{"id":24281498,"url":"https://github.com/amitavroy/laravel-sort-and-filter","last_synced_at":"2026-02-28T05:02:50.205Z","repository":{"id":56947130,"uuid":"271022486","full_name":"amitavroy/laravel-sort-and-filter","owner":"amitavroy","description":"A laravel package to sort and filter Eloquent models using the Request params","archived":false,"fork":false,"pushed_at":"2024-01-01T17:15:33.000Z","size":56,"stargazers_count":6,"open_issues_count":1,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-12-26T06:16:41.363Z","etag":null,"topics":["laravel","laravel-package","php"],"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/amitavroy.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-06-09T14:17:34.000Z","updated_at":"2024-05-27T02:59:07.000Z","dependencies_parsed_at":"2023-02-01T03:31:31.723Z","dependency_job_id":null,"html_url":"https://github.com/amitavroy/laravel-sort-and-filter","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amitavroy%2Flaravel-sort-and-filter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amitavroy%2Flaravel-sort-and-filter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amitavroy%2Flaravel-sort-and-filter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amitavroy%2Flaravel-sort-and-filter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/amitavroy","download_url":"https://codeload.github.com/amitavroy/laravel-sort-and-filter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234143391,"owners_count":18786140,"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":["laravel","laravel-package","php"],"created_at":"2025-01-16T03:00:01.082Z","updated_at":"2025-09-25T01:30:39.941Z","avatar_url":"https://github.com/amitavroy.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Laravel Sort and Filter\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/amitavroy/laravel-sort-and-filter.svg?style=flat-square)](https://packagist.org/packages/amitavroy/laravel-sort-and-filter)\n![Tests](https://github.com/amitavroy/laravel-sort-and-filter/workflows/Tests/badge.svg)\n[![Total Downloads](https://img.shields.io/packagist/dt/amitavroy/laravel-sort-and-filter.svg?style=flat-square)](https://packagist.org/packages/amitavroy/laravel-sort-and-filter)\n\nThis package allows you to sort, filter and even search Eloquent models using the Request object.\n\nNo need to write conditional code inside you controller to handle sort, filter or search parameters coming from front end through URL (for example from a Javascrpt application)\n\nJust pass the request object and the sorting and filters should automatically work.\n\n## Installation\n\nYou can install the package via composer:\n\n```bash\ncomposer require amitavroy/laravel-sort-and-filter\n```\n\nYou can publish the config file with:\n\n```bash\nphp artisan vendor:publish --provider=\"Amitav\\SortAndFilter\\SortAndFilterServiceProvider\" --tag=\"config\"\n```\n\n## Usage\n\nThis pacakge provides with a Trait which you need to use in any Model that you want to have the ability to sort, filter or search. For example, in the user model, you need to add\n\n```\nuse SortAndFilter;\n```\n\nOnce done, you can add the sort, filter or search function to the Model inside a query and pass the request object directly as show below.\n\nYou can sort and/or filter on any model after adding the trait as shown below:\n\n```php\nUser::query()\n    -\u003esort($request)\n    -\u003efilter($request)\n    -\u003eget();\n```\n\nWith this, you have the ability to pass paramters through URL like this:\n\n```\nhttp://localhost:8000?sortBy=name\u0026sortOrder=desc\nhttp://localhost:8000?filterBy=name\u0026filterValue=Amitav\n```\n\nIf you want to control which fields can be filtered and which fields can be sorted, then you can create a protected field in your model with name **\\$sortable** to control sort fields. And, create a protected field with name **\\$filterable** to control which fields can be used to filter.\n\nYou can even search on any model as shown below:\n\n```php\nUser::query()\n    -\u003esearch($request)\n    -\u003eget();\n```\n\nNOTE: The search is going to be a database query and the package runs a like query. And hence, be careful about the number of string that you allow in validation before you send the request object for search. Internally, the query will be something like:\n\n```mysql\nSELECT * FROM user WHERE name LIKE \"amit%\";\n```\n\n## Testing\n\n```bash\ncomposer test\n```\n\n## Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.\n\n## Contributing\n\nPlease see [CONTRIBUTING](CONTRIBUTING.md) for details.\n\n## Security\n\nIf you discover any security related issues, please email reachme@amitavroy.com instead of using the issue tracker.\n\n## Credits\n\n-   [Amitav Roy](https://github.com/amitavroy)\n-   [All Contributors](../../contributors)\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%2Famitavroy%2Flaravel-sort-and-filter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Famitavroy%2Flaravel-sort-and-filter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famitavroy%2Flaravel-sort-and-filter/lists"}