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

ActivePackage

kalimeromk/filterable
=====================

A Laravel package that simplifies dynamic filtering and searching across models and their relationships, eliminating repetitive query code.

v1.6(2y ago)52.6k↓50%1MITPHPPHP &gt;=8.0

Since Apr 21Pushed 1y ago2 watchersCompare

[ Source](https://github.com/KalimeroMK/filterable)[ Packagist](https://packagist.org/packages/kalimeromk/filterable)[ RSS](/packages/kalimeromk-filterable/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (8)Dependencies (1)Versions (8)Used By (0)

Filterable - Laravel Package for Dynamic Filtering
==================================================

[](#filterable---laravel-package-for-dynamic-filtering)

**Filterable** is a Laravel package designed to simplify dynamic filtering and searching across models and their relationships, eliminating the need for repetitive query code. It provides an easy-to-use trait and macros for building powerful, dynamic query filters.

---

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

[](#installation)

1. Require the package via Composer:

    ```
    composer require kalimeromk/filterable
    ```
2. The package supports auto-discovery, so no manual registration of the service provider is needed. However, if you are using an older Laravel version, add the service provider to your `config/app.php`:

    ```
    'providers' => [
        Kalimeromk\Filterable\PackageServiceProvider::class,
    ];
    ```

---

Usage
-----

[](#usage)

### 1. Using `whereLike` Macro

[](#1-using-wherelike-macro)

The `whereLike` macro allows you to perform "LIKE" searches on multiple fields, including related model fields.

#### Example:

[](#example)

```
use App\Models\User;

$users = User::query()
    ->whereLike(['name', 'email'], 'John')
    ->get();
```

This will return all users where the `name` or `email` fields contain the string "John".

#### Searching on Related Models:

[](#searching-on-related-models)

```
$users = User::query()
    ->whereLike(['posts.title', 'posts.content'], 'Laravel')
    ->with('posts')
    ->get();
```

This will return all users who have posts with a title or content containing the string "Laravel".

---

### 2. Using the `Filterable` Trait

[](#2-using-the-filterable-trait)

The `Filterable` trait allows you to dynamically filter a model based on specific criteria, including `LIKE` queries, boolean fields, and `whereIn` filters, as well as range filters like `_min` and `_max`.

#### Setup:

[](#setup)

Add the `Filterable` trait to your model:

```
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Kalimeromk\Filterable\Traits\Filterable;

class User extends Model
{
    use Filterable;

    protected $fillable = ['name', 'email', 'is_active'];

    // Define fields for specific filters
    protected $boolFields = ['is_active'];
    protected $likeFields = ['name', 'email'];
}
```

#### Example Controller:

[](#example-controller)

```
use App\Models\User;
use Illuminate\Http\Request;

class UserController extends Controller
{
    public function index(Request $request)
    {
        $filters = $request->only(['name', 'email', 'is_active', 'age_min', 'age_max']);

        $users = User::filter($filters)->get();

        return response()->json($users);
    }
}
```

#### Example API Request:

[](#example-api-request)

- **Request:**```
    GET /users?name=Jane&is_active=true&age_min=25&age_max=35

    ```
- **Result:**Returns all active users (`is_active = true`) whose name contains "Jane" and whose age is between 25 and 35.

---

Testing the Package
-------------------

[](#testing-the-package)

This package uses [Orchestra Testbench](https://github.com/orchestral/testbench) for testing.

### Running Tests

[](#running-tests)

To run the tests:

1. Install the dependencies:

    ```
    composer install
    ```
2. Run PHPUnit:

    ```
    vendor/bin/phpunit
    ```

---

License
-------

[](#license)

This package is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance32

Infrequent updates — may be unmaintained

Popularity25

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 96.7% 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 ~97 days

Recently: every ~70 days

Total

7

Last Release

903d ago

PHP version history (2 changes)v1PHP &gt;=7.4.0

v1.1PHP &gt;=8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/472c4da0220f15747dd81d3a27ffbba022a06ab20f64a367ddcaacd790d812d7?d=identicon)[KalimeroMK](/maintainers/KalimeroMK)

---

Top Contributors

[![KalimeroMK](https://avatars.githubusercontent.com/u/24772657?v=4)](https://github.com/KalimeroMK "KalimeroMK (29 commits)")[![zhivkoApo](https://avatars.githubusercontent.com/u/66877019?v=4)](https://github.com/zhivkoApo "zhivkoApo (1 commits)")

---

Tags

filteringfilterslaravelphplaravel

### Embed Badge

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

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

###  Alternatives

[rtconner/laravel-likeable

Trait for Laravel Eloquent models to allow easy implementation of a 'like' or 'favorite' or 'remember' feature.

394388.0k5](/packages/rtconner-laravel-likeable)[hemp/presenter

Easy Model Presenters in Laravel

247592.6k1](/packages/hemp-presenter)[slowlyo/owl-admin

基于 laravel、amis 开发的后台框架~

61214.2k26](/packages/slowlyo-owl-admin)

PHPackages © 2026

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