PHPackages                             dmarte/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. dmarte/filterable

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

dmarte/filterable
=================

Easy to use package to filter Laravel Eloquent records.

v1.0.6(4y ago)3881[1 PRs](https://github.com/dmarte/filterable/pulls)MITPHP

Since May 25Pushed 4y ago1 watchersCompare

[ Source](https://github.com/dmarte/filterable)[ Packagist](https://packagist.org/packages/dmarte/filterable)[ RSS](/packages/dmarte-filterable/feed)WikiDiscussions main Synced 3d ago

READMEChangelog (6)Dependencies (1)Versions (4)Used By (0)

Filterable
==========

[](#filterable)

A Laravel library to handle filters for Eloquent models or Scout database records with a single API.

1. [How it works](#how-it-works)
2. [Implementation](#implementation)
3. [Pagination](#pagination)
4. [Reserved query string parameters](#reserved-query-string-parameters)
5. [Limiting the Full-Text columns check](#limiting-the-full-text-columns-check)
6. [Filterable queries](#filterable-queries)
7. [Resource response](#resource-response)

### How it works

[](#how-it-works)

Filterable automatically will perform the required implementation to fetch records from an eloquent model. At first, will try to check if want to perform a Laravel Scout search, or a full eloquent model search.

It also supports Full text search.

```
IMPORTANT NOTE:
Filterable will return a JsonResource if the HTTP Accept is present and is application/json.

```

#### Implementation

[](#implementation)

```
// IN YOUR ELOQUENT MODEL

namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use \Dmarte\Filterable\Filterable;

class Contact extends Model {
    // Just, import the trait filterable
    use Filterable;
}
```

```
// IN YOUR CONTROLLER

use App\Models\Contact;
use Illuminate\Support\Facades\Request;
use Illuminate\Http\Resources\Json\JsonResource;
use App\Http\Controllers\Controller;

class ContactController extends Controller {

    public function index(Request $request) : JsonResource{
        // Just call the static function "filter" to perform the query.
        return Contact::filter($request);

    }
}
```

### Pagination

[](#pagination)

Filterable package by default will return a **collection of records**, if you would like to get the paginator format you must include the query string `paginator=true` in the request.

With `?paginator=false` response will be:

```
[]
```

With `?paginator=true` response will be:

```
{
 "data": Array,
 "meta": {
  "per_page": Number
  "current_page": Number
  "last_page": Number
  "from": Number
  "to": Number
 }
}
```

### Reserved `query string` parameters

[](#reserved-query-string-parameters)

In order to change the expected results in search, filterable check with params you have in your request.

ParameterDefaultDescriptionExample`with_trashed`falseAllow to include `deleted` records in the result set.`?with_trashed=true``per_page`15Determine the number or records to get in the query.`?per_page=20``with`nullAn `array` or `string` with the list of model relations to include.`with[]=relation1&with[]=relation2``search`nullA string to activate the full-text search support.`?search=John%sdoe``paginator`falseEnable or disable the paginator format in data response.### Limiting the Full-Text columns check

[](#limiting-the-full-text-columns-check)

By specifying the list of columns that should be full-text searchable you can globally search based on generic criterea.

```
// IN YOUR MODEL
// just override the method that indicate
// the columns should be full-text filterable
/**
 * @return array
 */
protected static function fullTextColumns(): array
{
    return [
        'name',
        'description',
        //...
    ];
}
```

### Filterable queries

[](#filterable-queries)

You could create your own logic for each column when you override the method `filterableQueries`.

#### **IMPORTANT**

[](#important)

You must be sure to return an instance of `Illuminate\Support\Collection` with each callback. The filterable engine will check the "key" on the collection to match the request "key", then will expect each value should be a callback function that perform your desired query.

#### Here is an example

[](#here-is-an-example)

```
    // IN YOUR MODEL
    protected function filterableQueries(): Collection
    {
        return collect([
            'team_id'    => fn(Builder $query, $column, $value) => $query->where($column, $value),
            'emitted_at' => function (Builder $query, $column, $value) {
                if (is_array($value)) {
                    return $query->whereBetween($column, $value);
                }

                return $query->where($column, $value);
            },
        ]);
    }
```

#### Resource response

[](#resource-response)

You could change the resource class used as response using the function `qualifiedResource`. With this `static` function you return the path of your resource.

> **NOTE**By default it will take the name of the model with the suffix `Resource`. Eg. for `\App\Models\User` model will try to find `\App\Http\Resources\UserResource`.

You can change this behavior overriding that function.

```
    protected static function qualifiedResource(): string
    {
        return \App\Http\Resources\ModelResource::class;
    }
```

#### Filter by multiple models

[](#filter-by-multiple-models)

Useful for global searches you could create a multi-model filter.

```
        // Add column filter that will be applied to all models.
        $request->merge([
            'team_id' => $request->user()->team_id,
        ]);

        $engine = new FilterableMultiple(
            models: [
            Service::class,
            Product::class,
        ],
            request: $request
        );

        // Customize the query used for a given model
        $engine->query(Service::class, function (Builder $query) {
            $query->where('kind', 'service_custome_value');
        });

        // Return the collection
        return $engine->get()
```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~32 days

Total

3

Last Release

1752d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/2656804?v=4)[Delvi Marte](/maintainers/dmarte)[@dmarte](https://github.com/dmarte)

---

Top Contributors

[![dmarte](https://avatars.githubusercontent.com/u/2656804?v=4)](https://github.com/dmarte "dmarte (24 commits)")

### Embed Badge

![Health badge](/badges/dmarte-filterable/health.svg)

```
[![Health](https://phpackages.com/badges/dmarte-filterable/health.svg)](https://phpackages.com/packages/dmarte-filterable)
```

###  Alternatives

[doctrine/orm

Object-Relational-Mapper for PHP

10.2k285.3M6.2k](/packages/doctrine-orm)[mongodb/mongodb

MongoDB driver library

1.6k64.0M546](/packages/mongodb-mongodb)[reliese/laravel

Reliese Components for Laravel Framework code generation.

1.7k3.4M16](/packages/reliese-laravel)[stancl/virtualcolumn

Eloquent virtual column.

826.8M13](/packages/stancl-virtualcolumn)[pmatseykanets/laravel-scout-postgres

PostgreSQL Full Text Search Driver for Laravel Scout

164213.7k2](/packages/pmatseykanets-laravel-scout-postgres)[orchestra/database

Database Component for Orchestra Platform

201.4M578](/packages/orchestra-database)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
