PHPackages                             james.xue/laravel-eloquent-filter - 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. james.xue/laravel-eloquent-filter

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

james.xue/laravel-eloquent-filter
=================================

An Eloquent way to filter Eloquent Model

v3.1.0(3y ago)261[1 PRs](https://github.com/xiaoxuan6/laravel-eloquent-filter/pulls)MITPHPPHP &gt;=7.0CI passing

Since Aug 16Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/xiaoxuan6/laravel-eloquent-filter)[ Packagist](https://packagist.org/packages/james.xue/laravel-eloquent-filter)[ Fund](https://www.paypal.me/xuexiaoxuan)[ RSS](/packages/jamesxue-laravel-eloquent-filter/feed)WikiDiscussions v2.0 Synced 1mo ago

READMEChangelog (9)Dependencies (5)Versions (17)Used By (0)

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

[](#installation)

This package can be installed through Composer.

```
composer require james.xue/laravel-eloquent-filter

```

使用
--

[](#使用)

```
php artisan make:filter Test

```

修改生成文件命名空间
----------

[](#修改生成文件命名空间)

```
默认命名空间：App\Filters

先执行 php artisan vendor:publish --tag=filter
然后修改 config 中的 namespace

```

### TestFilter

[](#testfilter)

```
搜索默认数据库字段
    public function code($code)
    {
        return $this->builder->where('code', $code);
    }

    public function name()
    {
        return $this->builder->where('name', 'like', "%测试%");
    }

    public function mobile($mobile)
    {
        return $mobile ? $this->builder->where('mobile', $mobile) : $this->builder;
    }

 一对多
    public function title($title)
    {
        return $this->builder->whereHas('goods', function($q) use ($title){
            return $q->where('title', 'like', "%{$title}%");
        });
    }

```

### Controller、通过 url 筛选条件默认方法可以不写，默认搜索条件为 where($column, $keywords)

[](#controller通过-url-筛选条件默认方法可以不写默认搜索条件为-wherecolumn-keywords)

```
// http://baby.com/api/city?code=54526481&title=菁华粉底液（片装1.5mll）

public function index(TestFilter $testfilter)
{
    Test::filter($testfilter)->get();
    // Or $testfilter 可以省略，但是 TestFilter 文件必须存在，默认加载 `模型 + Filter`
    Test::filter()->get();

    // 支持固定筛选
    Test::filter($testfilter, 'name')->get();
    // Or
    Test::filter($testfilter, ['name'])->get();

    // 支持固定筛选带参数
    $mobile = "185513215";
    Test::filter($testfilter, ['mobile:'.$mobile])->get();

    // 支持自定义筛选方式，example：、like等
    $mobile = "185513215";
    Test::filter($testfilter, ['mobile:'.$mobile."|"])->get();
}

```

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance56

Moderate activity, may be stable

Popularity11

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 64.4% 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 ~94 days

Recently: every ~117 days

Total

16

Last Release

1044d ago

Major Versions

1.1.0 → 2.0.02020-06-11

2.0.0 → 3.0.02022-03-17

### Community

Maintainers

![](https://www.gravatar.com/avatar/2f8fdd2069c7594101452a5c802ae01209a31109d67a9299a67320752c30a1de?d=identicon)[xiaoxuan6](/maintainers/xiaoxuan6)

---

Top Contributors

[![xiaoxuan6](https://avatars.githubusercontent.com/u/32762220?v=4)](https://github.com/xiaoxuan6 "xiaoxuan6 (29 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (8 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (8 commits)")

---

Tags

searchlaravelmodeleloquentqueryfilter

###  Code Quality

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/jamesxue-laravel-eloquent-filter/health.svg)

```
[![Health](https://phpackages.com/badges/jamesxue-laravel-eloquent-filter/health.svg)](https://phpackages.com/packages/jamesxue-laravel-eloquent-filter)
```

###  Alternatives

[tucker-eric/eloquentfilter

An Eloquent way to filter Eloquent Models

1.8k4.8M26](/packages/tucker-eric-eloquentfilter)[mehdi-fathi/eloquent-filter

Eloquent Filter adds custom filters automatically to your Eloquent Models in Laravel.It's easy to use and fully dynamic, just with sending the Query Strings to it.

450191.6k1](/packages/mehdi-fathi-eloquent-filter)[jedrzej/searchable

Searchable trait for Laravel's Eloquent models - filter your models using request parameters

127259.1k5](/packages/jedrzej-searchable)[jedrzej/pimpable

Laravel 4/5/6 package that allows to dynamically filter, sort and eager load relations for your models using request parameters

105179.0k1](/packages/jedrzej-pimpable)[aldemeery/sieve

A simple, clean and elegant way to filter Eloquent models.

1396.3k](/packages/aldemeery-sieve)[lacodix/laravel-model-filter

A Laravel package to filter, search and sort models with ease while fetching from database.

17649.9k](/packages/lacodix-laravel-model-filter)

PHPackages © 2026

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