Download the PHP package amitavroy/laravel-sort-and-filter without Composer
On this page you can find all versions of the php package amitavroy/laravel-sort-and-filter. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package laravel-sort-and-filter
Laravel Sort and Filter
This package allows you to sort, filter and even search Eloquent models using the Request object.
No 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)
Just pass the request object and the sorting and filters should automatically work.
Installation
You can install the package via composer:
You can publish the config file with:
Usage
This 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
Once 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.
You can sort and/or filter on any model after adding the trait as shown below:
With this, you have the ability to pass paramters through URL like this:
If 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.
You can even search on any model as shown below:
NOTE: 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:
Testing
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
Credits
- Amitav Roy
- All Contributors
License
The MIT License (MIT). Please see License File for more information.