faisal50x / query-filter
Laravel Eloquent models filter based on query parameters.
v1.0.6
2023-10-23 08:49 UTC
Requires
- php: ^7.1|^7.2|^7.3|^7.4|^8.0|^8.1
- illuminate/console: ^5.6|^6.0|^7.0|^8.0|^9.0|^10.0
- illuminate/database: ^5.6|^6.0|^7.0|^8.0|^9.0|^10.0
- illuminate/support: ^5.6|^6.0|^7.0|^8.0|^9.0|^10.0
Requires (Dev)
- ext-json: *
- orchestra/testbench: ^4.0|^5.0|^6.0|^7.0|^8.0
- phpunit/phpunit: ^8.0|^9.0|^10.0
This package is auto-updated.
Last update: 2024-11-23 10:59:33 UTC
README
This is a simple package, It's can boost your productivity, make your code cleaner as well as simple.
Installation
You can install the package via composer:
composer require faisal50x/query-filter
Usage
Before
public function index($request){ $query = User::query(); if(request()->has('status')) { $query = $query->where('status', request()->get('status')); } if(request()->has('role')) { $query = $query->where('role', request()->get('role')); } $users = $query->get(); }
Now
public function index($request, UserFilter $filter){ //It's nice and clean $users = User::filter($filter)->get(); } // User Filter use Faisal50x\QueryFilter\QueryFilter; class UserFilter extends QueryFilter { public function status($query, $status){ return $query->whereStatus($status); } public function role($query, $role){ return $query->whereRole($role); } }
Testing
composer test
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email hello@imfaisal.me instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
Laravel Package Boilerplate
This package was generated using the Laravel Package Boilerplate.