PHPackages                             pointybeard/laravel-filterable-model - 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. [Search &amp; Filtering](/categories/search)
4. /
5. pointybeard/laravel-filterable-model

ActiveProject[Search &amp; Filtering](/categories/search)

pointybeard/laravel-filterable-model
====================================

Add filtering via http request query params to eloquent models

2.0.0(2y ago)22.0kMITPHPPHP &gt;=8.1.0

Since Jun 19Pushed 1y ago1 watchersCompare

[ Source](https://github.com/pointybeard/laravel-filterable-model)[ Packagist](https://packagist.org/packages/pointybeard/laravel-filterable-model)[ RSS](/packages/pointybeard-laravel-filterable-model/feed)WikiDiscussions main Synced 4w ago

READMEChangelogDependencies (18)Versions (5)Used By (0)

Laravel Filterable Model
========================

[](#laravel-filterable-model)

Add filtering via http request query params to Eloquent models in Laravel

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

[](#installation)

```
> composer require pointybeard/laravel-filterable-model
```

Usage
-----

[](#usage)

Extend your Eloquent models with `Pointybeard\FilterableModel\AbstractFilterableModel` and then use the trait `Pointybeard\FilterableModel\Traits\FilterableTrait`. This will add a new scope called `filter`, as well as the following methods, to your model:

- `getFilterable()`
- `getSortable()`
- `getSortByDefault()`
- `getSortOrderDefault()`

Then, add protected properties `$filterable`, `$sortable`, `$sortByDefault`, and `$sortOrderDefault` to control the behaviour of filtering. E.g.

```
protected $filterable = ['title', 'category', 'tags', 'is_published'];
protected bool $sortable = true;
protected string $sortByDefault = 'published_at'; // default is 'created_at'
protected string $sortOrderDefault = 'desc'; // default is 'asc'
```

Finally, you can use the `->filter()` scope to filter results by passing an instance of `Filter`. E.g.

```
use App\Models\MyModel;
use Pointybeard\FilterableModel\Filter;

MyModel::filter(new Filter(
    filters: [
        'tag' => 'article',
        'is_published' => 1,
    ],
));
```

Alternatively, use the `Filter::fromRequest()` method to build a filter from request query params, e.g. in your controllers like so:

```
use App\Models\MyModel;
use Pointybeard\FilterableModel\Filter;

return response()->json(
    MyModel::filter(Filter::fromRequest($request))->get(),
    Response::HTTP_OK
);
```

By default, all comparisons are done by injecting an equals (`=`) where clause into the database calls. To use other comparisons, or add more complex logic, create a new class that extends `Pointybeard\FilterableModel\Filter` and add your own methods. For example, to use a `LIKE` comparison for your `tag` field and a boolean comparison for `is_published`:

```
use Pointybeard\FilterableModel\AbstractFilterableModel;
use Pointybeard\FilterableModel\Filter;
use Illuminate\Database\Eloquent\Builder;

Class MyModelFilter extends Filter
{
    public function tag(Builder $builder, AbstractFilterableModel $model, string $value): Builder
    {
        return $builder->where('tag', 'like', "%{$value}%");
    }

    public function is_published(Builder $builder, AbstractFilterableModel $model, string $value): Builder
    {
        // Convert a string representation of true/false into an actual boolean
        $value = in_array(strtolower($value), ['1', 'true', 'yes']) ? true : false;

        return $builder->where('protected', $value);
    }
}
```

Contributing
------------

[](#contributing)

We encourage you to contribute to this project. Please check out the [Contributing documentation](https://github.com/pointybeard/laravel-filterable-model/blob/master/CONTRIBUTING.md) for guidelines about how to get involved.

Support
-------

[](#support)

If you believe you have found a bug, please report it using the [GitHub issue tracker](https://github.com/pointybeard/laravel-filterable-model/issues).

Authors
-------

[](#authors)

- [Alannah Kearney](https://github.com/pointybeard)
- [All Contributors](https://github.com/pointybeard/laravel-filterable-model/contributors)

License
-------

[](#license)

"Laravel Filterable Model" is released under the MIT License. See [LICENCE](http://www.opensource.org/licenses/MIT) for details.

###  Health Score

33

—

LowBetter than 74% of packages

Maintenance35

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity59

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 ~228 days

Total

3

Last Release

963d ago

Major Versions

1.0.1 → 2.0.02023-09-18

PHP version history (2 changes)1.0.0PHP &gt;=8.0.2

2.0.0PHP &gt;=8.1.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/a37b0251aec347d8b00d31f1d063138e9e9da0e4cd276f481272f0b6a4af58e5?d=identicon)[pointybeard](/maintainers/pointybeard)

---

Top Contributors

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

###  Code Quality

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/pointybeard-laravel-filterable-model/health.svg)

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

###  Alternatives

[jeroen-g/explorer

Next-gen Elasticsearch driver for Laravel Scout.

397612.3k](/packages/jeroen-g-explorer)[swisnl/laravel-fulltext

Fulltext indexing and searching for Laravel

184104.5k5](/packages/swisnl-laravel-fulltext)[pressbooks/pressbooks

Pressbooks is an open source book publishing tool built on a WordPress multisite platform. Pressbooks outputs books in multiple formats, including PDF, EPUB, web, and a variety of XML flavours, using a theming/templating system, driven by CSS.

44643.1k1](/packages/pressbooks-pressbooks)[api-platform/laravel

API Platform support for Laravel

59126.4k6](/packages/api-platform-laravel)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

255.2k](/packages/aedart-athenaeum)

PHPackages © 2026

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