Skip to content

Laravel Filter is a laravel package to easily add filtering to your eloquent queries.

License

Notifications You must be signed in to change notification settings

emmadonjo/laravel-filter

Repository files navigation

Build Status Total Downloads Latest Stable Version License

Laravel Filter is a laravel package to easily add filtering to your eloquent queries.

You can add filtering capabilities to your eloquent queries:

  • Filter a single or multiple columns
  • Filter columns with list (array) of possible values

Usage

Install via:

    composer require emmadonjo/laravel-filter
    ...

    use Emmadonjo\LaravelFilter\Contracts\Filterable;
    use Emmadonjo\LaravelFilter\Concerns\HasFilter;

    class Post extends Model implements Filterable
    {
        use HasFilter;

        public function filterableColumns(): array
        {
            return [
                'slug',
                'author_id',
                'status'
            ];
        }
    }


    // filter posts
    $filters = ['author_id' => 1, 'status' => 'published'];

    Post::filter($filters)->get();

    // filter a post's column with multiple possible values
    $filters = ['status' => ['scheduled', 'draft']];

    Post::filter($filters)->get();

    // combine both
    $filters = [
        'status' => ['scheduled', 'draft'],
        'author_id' => 1
    ];

    Post::filter($filters)->get();

Changelog

Kindly see the releases for more information on what has changed recently.

Contributing

Pull requests are highly welcomed. Ensure you follow the PSR coding standards and meet static analysis level of 9.

License

The MIT License (MIT). Please see LICENSE for details.

About

Laravel Filter is a laravel package to easily add filtering to your eloquent queries.

Topics

Resources

License

Stars

Watchers

Forks

Languages