faisal50x/query-filter

Laravel Eloquent models filter based on query parameters.

v1.0.6 2023-10-23 08:49 UTC

This package is auto-updated.

Last update: 2024-10-23 10:54:05 UTC


README

Latest Version on Packagist Build Status Quality Score Total Downloads

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.