Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/atnic/eloquent-filters
Eloquent Filter Package for Laravel
https://github.com/atnic/eloquent-filters
Last synced: 17 days ago
JSON representation
Eloquent Filter Package for Laravel
- Host: GitHub
- URL: https://github.com/atnic/eloquent-filters
- Owner: Atnic
- License: mit
- Created: 2019-01-10T07:40:40.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2021-12-06T20:09:09.000Z (about 3 years ago)
- Last Synced: 2024-08-09T17:13:43.092Z (5 months ago)
- Language: PHP
- Size: 5.86 KB
- Stars: 0
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Filterable Eloquent
Easily filter Laravel Eloquent queries by using URL query strings.## Installation
Install the package via composer
```
composer require atnic/eloquent-filters
```## Usage
First you need to add Filterable trait and filters attribute to your model as the following:
```php
use Smartisan\Filters\Traits\Filterable;class User extends Model
{
use Filterable;
protected $filters = App\Filters\UserFilter::class;
}
```Then create UserFilter class and define your filters as public methods:
```php
use Smartisan\Filters\Filter;class UserFilter extends Filter
{
public function status($code)
{
return $this->builder->where('status', $code);
}
}
```Note that you are able to access the query builder instance of user by using ``$this->builder``.
Now in order to check for URL query strings and perform the corrosponding filter, you need to use ``User::filter($request)->get()``.
## Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.## Credits
* [Mohammed Isa](https://github.com/mohd-isa)
* [All Contributors](https://github.com/mohd-isa/laravel-settings/graphs/contributors)## License
The [MIT License (MIT)](https://github.com/mohd-isa/laravel-settings/blob/master/LICENSE.md). Please see License File for more information.