PHPackages                             mykeels/laravel-filters - 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. mykeels/laravel-filters

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

mykeels/laravel-filters
=======================

Provides a composable interface for data filtering with query strings

161.5k7[2 PRs](https://github.com/mykeels/laravel-filters/pulls)PHP

Since Sep 27Pushed 6y ago1 watchersCompare

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

READMEChangelogDependenciesVersions (3)Used By (0)

Laravel Filters
===============

[](#laravel-filters)

Imagine that ...

Filter with Query String
------------------------

[](#filter-with-query-string)

This URL:

```
/users?name=myk&age=21&company=rick-and-morty&sort_age=desc

```

automatically knew to filter the DB query by responding with users that have their

- name containing `myk`
- age as `21`
- company name containing `rick-and-morty`

and order the records by age in descending order, all without you having to write boilerplate code 😱.

Load Relationships
------------------

[](#load-relationships)

Or that you could automatically include a relationship for a model by adding a `?with_relationship` to the URL 😍, like:

[![laravel-filters](https://user-images.githubusercontent.com/11996508/43687436-08f61c1c-98cd-11e8-962b-cd32c2d3bfb3.gif)](https://user-images.githubusercontent.com/11996508/43687436-08f61c1c-98cd-11e8-962b-cd32c2d3bfb3.gif)

Hold your horses 😜, I'm about to show you how.

Setup
-----

[](#setup)

- Run `composer require mykeels/laravel-filters` in your terminal to pull the package in.

Usage
-----

[](#usage)

- In the Model class you wish to make filterable, use the `FilterableTrait` like:

```
