Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/emmadonjo/laravel-filter

Laravel Filter is a laravel package to easily add filtering to your eloquent queries.
https://github.com/emmadonjo/laravel-filter

eloquent laravel php

Last synced: 3 months ago
JSON representation

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

Awesome Lists containing this project

README

        


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:

```php
composer require emmadonjo/laravel-filter
```

```php

...

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](https://github.com/emmadonjo/laravel-filter/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](https://github.com/emmadonjo/laravel-filter/blob/master/LICENSE.md) for details.