PHPackages                             mayoz/eloquent-filterable - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. mayoz/eloquent-filterable

ActiveLibrary[Database &amp; ORM](/categories/database)

mayoz/eloquent-filterable
=========================

Query filter for your Eloquent models.

2.0.0(10y ago)91171MITPHPPHP &gt;=5.5.9

Since Mar 31Pushed 10y ago2 watchersCompare

[ Source](https://github.com/mayoz/eloquent-filterable)[ Packagist](https://packagist.org/packages/mayoz/eloquent-filterable)[ RSS](/packages/mayoz-eloquent-filterable/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (3)Versions (5)Used By (0)

Eloquent Filterable
===================

[](#eloquent-filterable)

With this package, you can optimize query clauses calling before or after the filter. You can manage your queries from a single interface.

Installation
------------

[](#installation)

[PHP](https://php.net/) 5.5.9+ or [HHVM](http://hhvm.com/), and [Composer](https://getcomposer.org/) are required.

To get the latest version of Eloquent Filterable, simply add the following line to the require block of your `composer.json` file:

```
"require": {
    "mayoz/eloquent-filterable": "~2.0"
}
```

You'll then need to run `composer install` or `composer update` to download it and have the autoloader updated. Or use to shortcut installed through terminal:

```
composer require mayoz/eloquent-filterable ~2.0
```

Usage
-----

[](#usage)

1. Create your query filters.
2. Create your Eloquent models.
3. Define `Filterable` trait and use the query filters in the Eloquent model.

### Create Filters

[](#create-filters)

All filters should be extend `Mayoz\Filter\Filter` abstract class. Thus, can be used `before` and `after` methods in your filters.

#### The Before Method

[](#the-before-method)

The `before` method responsible to position the **head** of the WHERE clause of the query. For example; we need `published = 1` of query WHERE clause. However, this clause would like to work on before the other clauses.

```
