PHPackages                             tanmaymishu/laravel-funnel - 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. tanmaymishu/laravel-funnel

ActiveLibrary

tanmaymishu/laravel-funnel
==========================

Bind http query string parameters to Eloquent model attributes.

v0.2.1(5y ago)104.1k1MITPHPPHP &gt;=7.2

Since Jan 21Pushed 5y ago1 watchersCompare

[ Source](https://github.com/tanmaymishu/laravel-funnel)[ Packagist](https://packagist.org/packages/tanmaymishu/laravel-funnel)[ RSS](/packages/tanmaymishu-laravel-funnel/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (2)Versions (9)Used By (0)

Laravel Funnel
==============

[](#laravel-funnel)

Filtering results based on the http query string parameter (`?key=value`) is one of the common tasks of everyday web development.

Laravel Funnel is an attempt to reduce the cognitive burden of applying and maintaining the filters.

Features
--------

[](#features)

- **Param-Attr binding:** Binds query string *parameters* to eloquent model *attributes*.
- **Code generation:** Generates filter classes with a simple command.
- **Multi-value params:** Makes multi-value parameters painless by allowing comma-delimited list in URL. Example: `http://example.com/posts?title=foo,bar`.
- **Sorting:** Creates "sort-aware" filters with a simple `--clause=orderBy` argument.
- **Searching:** Creates "search-aware" with a simple `--operator=like` argument.
- **Related model's attr binding:** Binds attribute from a related model easily with `relation.attribute` format: `--attribute=comments.body`
- **Eager-loading:** Funnel comes with eager-loading support out of the box. Pass your relation to the default `?with` query param. Example: `http://example.com/posts?with=comments,categories`.
- **Customization:** Query logic in generated filter classes can be overridden according to your need.

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

[](#installation)

Use the package manager [composer](https://getcomposer.org/) to install laravel-funnel.

```
composer require tanmaymishu/laravel-funnel
```

Usage
-----

[](#usage)

### Quick Start:

[](#quick-start)

Let's say you have a `Post` model and an attribute `published` and you want to filter all the posts that are published. The URL representation might look like this:

`http://example.com/posts?published=1`

Step 1: Run `php artisan funnel:filter Published`. A new `Published` class inside `app/Filters` directory will be created and the following configurations will be assumed:

- You have an attribute named `published`
- Your have a query string identifier named `published`
- Your desired query clause is `WHERE`
- The operator for the `WHERE` clause is `=`

Don't worry, all these "assumed defaults" can be overridden (See [CLI options](https://github.com/tanmaymishu/laravel-funnel#cli-options) below).

Step 2: Open the model (e.g. Post.php) where you want to use this filter in. Add these two lines in your class:

```
use HasFilters;
protected $filters = [];
```

Then add the filter class in the `$filters` array. Example:

```
