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
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();
Kindly see the releases for more information on what has changed recently.
Pull requests are highly welcomed. Ensure you follow the PSR coding standards and meet static analysis level of 9.
The MIT License (MIT). Please see LICENSE for details.