Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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.
- Host: GitHub
- URL: https://github.com/emmadonjo/laravel-filter
- Owner: emmadonjo
- License: mit
- Created: 2024-09-18T08:04:43.000Z (3 months ago)
- Default Branch: main
- Last Pushed: 2024-09-18T10:34:59.000Z (3 months ago)
- Last Synced: 2024-09-26T21:01:27.720Z (3 months ago)
- Topics: eloquent, laravel, php
- Language: PHP
- Homepage: https://github.com/emmadonjo/laravel-filter
- Size: 42 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
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:
```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.