PHPackages                             behamin/bfilters - 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. behamin/bfilters

ActiveLibrary

behamin/bfilters
================

A package for customized filtering on eloquent models

v1.6.1(2y ago)01.7kMITPHPPHP ^7.4|^8.0

Since Jul 7Pushed 2y ago3 watchersCompare

[ Source](https://github.com/behaminplus/bfilter)[ Packagist](https://packagist.org/packages/behamin/bfilters)[ RSS](/packages/behamin-bfilters/feed)WikiDiscussions master Synced 4d ago

READMEChangelog (2)Dependencies (2)Versions (18)Used By (0)

Behamin Filter
==============

[](#behamin-filter)

apply auto filters in Eloquent.
with this package, easily apply filters, sort and paginatation on Eloquent models and their relations.
with query string parameters.

### Installation

[](#installation)

```
composer require behamin/bfilters

```

### Updating your Eloquent Models

[](#updating-your-eloquent-models)

Your models should use the `HasFilter` trait:

```
use BFilters\Traits;

class MyModel extends Eloquent
{
    use HasFilter;

    // define fields for full text serach as "searchable" or "fillable"
    protected $searchable = [
    'first_name',
    'last_name'
    ];
}

```

### Create Filter Class

[](#create-filter-class)

```
php artisan make:filter {name}

for example:
php artisan make:filter UserFilter

```

### In Created Filter Class

[](#in-created-filter-class)

```
use Illuminate\Http\Request;

class UserFilter extends Filter
{
    public function __construct(Request $request)
    {
        parent::__construct($request);

        $this->relations = [
            //actual name of relation defined in original model
            'relationName1' => [
                'searchName1' => 'Original column1 Name in Relation table',
                'searchName2' => 'Original column2 Name in Relation table',
                'searchName3' => 'Original column3 Name in Relation table',

                //if searchName and original column name is same
                'Original column4 Name in Relation table'
            ],

            'posts' => [
                // in this case when you set posted_at as your filter the filter will applied on 'created_at' field of original table
                'posted_at' => 'created_at',
                'title',
                'topic',
            ],
        ];
        // you set this variabe if you want to have sum of your entries based of a specific field (f.e id here)
        $this->sumField = 'id';
        // define valid eager loading relationships to protect loading unwanted data
        $this->validWiths = ['comments', 'tags'];
    }
}

```

### Usage

[](#usage)

In controllers

```
public function index(YourModelFilter $filters): Response
{
    [$entries, $count, $sum] = YourModel::filter($filters);
}

```

In Request

```
filter:{
        "sort":[
                { "field": "created_at", "dir": "asc" },
                { "field": "first_name", "dir": "desc" }
         ],
         "page":{ "limit": 10, "offset": 0 },
         "filters":[
                    //(first_name LIKE '%alireza%' or last_name = '%bahram%') and (mobile LIKE '%9891%')
                    [
                       //use "or" for fields in same array & use "and" for fields in different array
                       {"field": "first_name", "op": "like", "value":  "alireza"},
                       {"field": "last_name", "op": "=", "value":  "bahram"}
                    ],
                    [
                        {"field": "mobile", "op": "like", "value": "9891"}
                    ],
                    [
                        //full search : search a string in fields you set in its model "searchable" or "fillable" arrays
                        {"value" : "al"}
                    ]
         ],
         "with":[
            "comments",
            "tags"
         ]
}

```

Query String Samples:
---------------------

[](#query-string-samples)

### pagination per\_page=10 page=0 :

[](#pagination-per_page10-page0-)

?filter={"page":{"limit": 10,"offset": 0}}

### pagination per\_page=20 and page=0 (sort\_by id desc) :

[](#pagination-per_page20-and-page0-sort_by-id-desc-)

?filter=%7B%22page%22:%7B%22limit%22:20,%22offset%22:0%7D,%22sort%22:\[%7B%22field%22:%22id%22,%22dir%22:%22desc%22%7D\]%7D

### like before field comment like aaaaaaaaa :

[](#like-before-field-comment-like-aaaaaaaaa-)

?filter=%7B%22page%22:%7B%22limit%22:20,%22offset%22:0%7D,%22sort%22:\[%7B%22field%22:%22id%22,%22dir%22:%22desc%22%7D\],%22filters%22:\[\[%7B%22field%22:%22comment%22,%22op%22:%22like%22,%22value%22:%22aaaaaaaa%22%7D\]\]%7D

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

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

Recently: every ~202 days

Total

16

Last Release

1041d ago

PHP version history (4 changes)v1.0.1PHP ^7.0

1.1.0PHP ^7.2|^7.3|^7.4

1.4.1PHP ^7.2|^7.3|^7.4|^8.0

v1.6PHP ^7.4|^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/75c05a67e6f24580b5b5421cc09fef166a6d290ba79bb8efc8bbe78fd5cbe8f7?d=identicon)[hebrahimzadeh](/maintainers/hebrahimzadeh)

![](https://www.gravatar.com/avatar/3ee1cdf1958a1862e71950b30d67116c57aa2f351f0defb75a17a5c761dfe2fc?d=identicon)[behamin-admin](/maintainers/behamin-admin)

---

Top Contributors

[![alirezabahram7](https://avatars.githubusercontent.com/u/46995989?v=4)](https://github.com/alirezabahram7 "alirezabahram7 (37 commits)")[![Hebrahimzadeh](https://avatars.githubusercontent.com/u/38420287?v=4)](https://github.com/Hebrahimzadeh "Hebrahimzadeh (31 commits)")[![saber13812002](https://avatars.githubusercontent.com/u/3294604?v=4)](https://github.com/saber13812002 "saber13812002 (4 commits)")[![meysamfard](https://avatars.githubusercontent.com/u/39233907?v=4)](https://github.com/meysamfard "meysamfard (2 commits)")[![mahmooddelta](https://avatars.githubusercontent.com/u/30744647?v=4)](https://github.com/mahmooddelta "mahmooddelta (2 commits)")[![mhabedini](https://avatars.githubusercontent.com/u/13943537?v=4)](https://github.com/mhabedini "mhabedini (2 commits)")[![omalizadeh](https://avatars.githubusercontent.com/u/12392549?v=4)](https://github.com/omalizadeh "omalizadeh (1 commits)")

### Embed Badge

![Health badge](/badges/behamin-bfilters/health.svg)

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

###  Alternatives

[anourvalar/eloquent-serialize

Laravel Query Builder (Eloquent) serialization

11320.2M21](/packages/anourvalar-eloquent-serialize)[namu/wirechat

A Laravel Livewire messaging app for teams with private chats and group conversations.

54324.5k](/packages/namu-wirechat)[statamic-rad-pack/runway

Eloquently manage your database models in Statamic.

135192.6k5](/packages/statamic-rad-pack-runway)

PHPackages © 2026

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