emmadonjo / laravel-filter
A laravel package to easily add filtering to your eloquent queries
v0.0.2
2024-09-18 10:33 UTC
Requires
- php: >=8
Requires (Dev)
- orchestra/testbench: ^9.4
- phpstan/phpstan: ^1.12
- phpunit/phpunit: ^11.3
README
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.