This is a simple package, It's can boost your productivity, make your code cleaner as well as simple.
You can install the package via composer:
composer require faisal50x/query-filter
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();
}
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);
}
}
composer test
Please see CHANGELOG for more information what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.
This package was generated using the Laravel Package Boilerplate.