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

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

morningtrain/laravel-filters
============================

Query filters for Laravel

2.14.0(3y ago)12.8k1GPL-3.0-onlyPHPPHP ^7.2|^8.0

Since Mar 22Pushed 3y ago3 watchersCompare

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

READMEChangelogDependencies (4)Versions (55)Used By (1)

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

[](#laravel-filters)

This package provides a series of filters that can be used to constrain a Laravel DB Query based on request values.

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

[](#installation)

Via Composer

```
$ composer require morningtrain/laravel-filters
```

Included Filters
----------------

[](#included-filters)

All filters can be used using the base Filter class at: `MorningTrain\Laravel\Filters\Filter`. It should not be confused with `MorningTrain\Laravel\Filters\Filters\Filter`that are the base class all filters are extending.

### Basic

[](#basic)

Filter by a basic variable static variable.

The following example look for `filter_request_parameter`in the request, and apply it to the query for the column of the same name.

```
Filter::by('filter_request_parameter')
```

It corresponds to:

```
$q->where(
    'filter_request_parameter',
    '=',
    request()->get('filter_request_parameter')
)
```

Like in the following example, it is possible to add a closure as the second parameter.

The closure will get the query as well as the filter value as parameters. It makes it possible to apply some custom logic.

```
Filter::by('filter_request_parameter', function($query, $value) {
    /// Custom logic for applying $value to $query
})
```

### Always

[](#always)

Always run a closure and apply something to the query.

```
Filter::always(function($query) {

})
```

### With

[](#with)

Eager load relations on the query.

```
Filter::with(['company', 'roles'])
```

### Paginate

[](#paginate)

Apply pagination to the query. It is important that this filter is applied last.

It expects the request values `$page` and `$per_page`to be present.

```
Filter::paginate()
```

### Order

[](#order)

The order filter can be configured to sort the data by specific columns or using scopes.

To specify the columns to sort by, call the `only` method on the filter. The following example will look for `sort[id]` and `sort[created_at]` in the request.

The values of `sort[]` can be either *asc* or *desc*.

```
Filter::order()->only(['id', 'created_at'])
```

Calling the scope method, it is possible to also configure any scopes to be used. It will be looking in the request for any sort keys that match the scope name.

```
Filter::order()
    ->only(['id', 'created_at'])
    ->scopes(['orderByName'])
```

Default values can also easily be added:

```
Filter::order()
    ->only(['id', 'created_at'])
    ->scopes(['orderByName'])
    ->defaultValue(['orderByName' => 'desc'])
```

Credits
-------

[](#credits)

This package is developed and actively maintained by [Morningtrain](https://morningtrain.dk).

```
 _- _ -__ - -- _ _ - --- __ ----- _ --_
(         Morningtrain, Denmark         )
 `---__- --__ _ --- _ -- ___ - - _ --_ ´
     o
    .  ____
  _||__|  |  ______   ______   ______
 (        | |      | |      | |      |
 /-()---() ~ ()--() ~ ()--() ~ ()--()
--------------------------------------

```

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity78

Established project with proven stability

 Bus Factor1

Top contributor holds 76.6% 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 ~28 days

Recently: every ~150 days

Total

54

Last Release

1101d ago

Major Versions

1.3.1 → 2.0.02020-12-08

PHP version history (3 changes)1.0PHP &gt;=7.1

1.0.19PHP ^7.2

2.10.1PHP ^7.2|^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/278725?v=4)[morningtrain](/maintainers/morningtrain)[@morningtrain](https://github.com/morningtrain)

---

Top Contributors

[![bjarnebonde](https://avatars.githubusercontent.com/u/5835042?v=4)](https://github.com/bjarnebonde "bjarnebonde (49 commits)")[![Mat-Gr](https://avatars.githubusercontent.com/u/22744066?v=4)](https://github.com/Mat-Gr "Mat-Gr (15 commits)")

### Embed Badge

![Health badge](/badges/morningtrain-laravel-filters/health.svg)

```
[![Health](https://phpackages.com/badges/morningtrain-laravel-filters/health.svg)](https://phpackages.com/packages/morningtrain-laravel-filters)
```

###  Alternatives

[swisnl/laravel-fulltext

Fulltext indexing and searching for Laravel

184104.5k6](/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)[aedart/athenaeum

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

245.2k](/packages/aedart-athenaeum)[api-platform/laravel

API Platform support for Laravel

59126.4k6](/packages/api-platform-laravel)

PHPackages © 2026

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