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

https://github.com/mcklayin/query-filter


https://github.com/mcklayin/query-filter

laravel queryfilter

Last synced: 6 months ago
JSON representation

Awesome Lists containing this project

README

          

# QueryFilter

Easily create filters for your Eloquent model.

Based on [Jeffray Way's Laracast tutorial](https://github.com/laracasts/Dedicated-Query-String-Filtering/).

## Installation

The library is currently not available on Composer, so you have to declare it manually in your `composer.json`.

To do this, add the following in your `composer.json` :

```json
{
"require" : {
"mcklayin/query-filter": "dev-master"
},
"repositories": [
{
"type": "vcs",
"url": "https://github.com/mcklayin/query-filter"
}
]
}
```

Or type in console:
composer require "mcklayin/query-filter @dev"

## Usage

- Create your model filters, for exemple in a `App\Http\Filters` namespace :

```php
builder->where('foo', 'bar');
//or
//return $this->where('foo', 'bar');
}
}
```

- Then, add the `FilterableTrait` on your model to allow the use of `MyModel::filter()` :

```php
get();

return response()->json(compact('data'));
}
}
```