PHPackages                             inovanti-bank/inovanti-advanced-query-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. [Database &amp; ORM](/categories/database)
4. /
5. inovanti-bank/inovanti-advanced-query-filters

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

inovanti-bank/inovanti-advanced-query-filters
=============================================

Componente de filtros avançados para Laravel

v1.0.1(1y ago)16MITPHPPHP ^8.2

Since Jan 6Pushed 1y agoCompare

[ Source](https://github.com/Inovanti-Bank/inovanti-advanced-query-filters)[ Packagist](https://packagist.org/packages/inovanti-bank/inovanti-advanced-query-filters)[ RSS](/packages/inovanti-bank-inovanti-advanced-query-filters/feed)WikiDiscussions production Synced 1mo ago

READMEChangelogDependencies (4)Versions (6)Used By (0)

Inovanti Advanced Query Filters
===============================

[](#inovanti-advanced-query-filters)

[![Latest Stable Version](https://camo.githubusercontent.com/4b2ad8a41985998b3b1c58cf79f7a4e9ca9e7d7f9510d89de03b13b1f93d7719/68747470733a2f2f706f7365722e707567782e6f72672f696e6f76616e74692d62616e6b2f696e6f76616e74692d616476616e6365642d71756572792d66696c746572732f76)](//packagist.org/packages/inovanti-bank/inovanti-advanced-query-filters)[![Total Downloads](https://camo.githubusercontent.com/4124bffed9282f088b1a5fd8856939ff0d0304bc1e053fedb8324177082c7256/68747470733a2f2f706f7365722e707567782e6f72672f696e6f76616e74692d62616e6b2f696e6f76616e74692d616476616e6365642d71756572792d66696c746572732f646f776e6c6f616473)](//packagist.org/packages/inovanti-bank/inovanti-advanced-query-filters)[![License](https://camo.githubusercontent.com/0bb19f6a617b12eefc9578b255585c87468fe235e3fbc3a7543ae0c90a855355/68747470733a2f2f706f7365722e707567782e6f72672f696e6f76616e74692d62616e6b2f696e6f76616e74692d616476616e6365642d71756572792d66696c746572732f6c6963656e7365)](//packagist.org/packages/inovanti-bank/inovanti-advanced-query-filters)

Inovanti Advanced Query Filters is a Laravel package that provides an easy and flexible way to apply advanced query filters to your Eloquent queries. It supports various types of filters including date, numeric, string, array, boolean, range, and relation filters.

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

[](#installation)

To install the package, you can use Composer:

```
composer require inovanti-bank/inovanti-advanced-query-filters
```

Usage
-----

[](#usage)

### Basic Usage

[](#basic-usage)

You can use the provided filters to apply various types of filters to your Eloquent queries. Here is an example of how to use the `FilterService`:

```
try {
    $results = User::query()->get();

    return response()->json([
        'filters' => request()->get('filters', []),
        'default_sort' => ['field' => 'created_at', 'direction' => 'desc'],
        'pagination' => ['limit' => 10, 'offset' => 0],
        'data' => $results,
    ]);
    } catch (Exception $e) {
    return response()->json(['error' => $e->getMessage()], 400);
}
```

Configuring Filters in Models
-----------------------------

[](#configuring-filters-in-models)

You can configure the filters directly in your Eloquent models. This way, the filters will always be available whenever a query is executed on the model.

### Example

[](#example)

```
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use InovantiBank\AdvancedQueryFilters\Services\FilterService;
use InovantiBank\AdvancedQueryFilters\Services\Filters\StringFilter;
use InovantiBank\AdvancedQueryFilters\Services\Filters\NumericFilter;
use InovantiBank\AdvancedQueryFilters\Services\Filters\DateFilter;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Facades\Log;
use Exception;

class User extends Model
{
    public static function boot()
    {
        parent::boot();

        static::addGlobalScope('filters', function (Builder $query) {

            $filters = request()->get('filters', []);

            if (empty($filters) && request()->isJson()) {
                $filters = request()->input('filters', []);
            }

            if (! empty($filters)) {

                $formattedFilters = [];
                foreach ($filters as $filter) {
                    $formattedFilters[$filter['field']] = $filter;
                }

                $filterService = new FilterService([
                    'name' => StringFilter::class,
                    'age' => NumericFilter::class,
                    'status' => ArrayFilter::class,
                    'email' => StringFilter::class,
                    'created_at' => DateFilter::class,
                    'is_active' => BooleanFilter::class,
                    'price' => NumericFilter::class,
                    'deleted_at' => NullFilter::class,
                    'range_field' => RangeFilter::class,
                    'profile.phone' => RelationFilter::class,
                    'profile.bio' => RelationFilter::class,
                ]);

                if (request()->has('filters')) {
                    try {
                        $filterService->applyFilters($query, $formattedFilters);
                    } catch (Exception $e) {
                        Log::error('Erro ao aplicar filtros: '.$e->getMessage());
                    }
                }
            }
        });
    }
}
```

Example JSON for Filters
------------------------

[](#example-json-for-filters)

Here are examples of the JSON structure that the frontend should send in the body of the request to apply the filters correctly:

### Date Filter

[](#date-filter)

```
{
  "filters": [
    {
      "field": "created_at",
      "operator": "between",
      "from": "2022-01-01",
      "to": "2022-12-31"
    },
    {
      "field": "created_at",
      "operator": "",
      "number": 25
    },
    {
      "field": "salary",
      "operator": "between",
      "from": 30000,
      "to": 60000
    }
  ]
}
```

### String Filter

[](#string-filter)

```
{
  "filters": [
    {
      "field": "name",
      "operator": "like",
      "string": "John"
    },
    {
      "field": "email",
      "operator": "not like",
      "string": "@example.com"
    }
  ]
}
```

### Array Filter

[](#array-filter)

```
{
  "filters": [
    {
      "field": "status",
      "operator": "in",
      "array": ["active", "pending"]
    },
    {
      "field": "tags",
      "operator": "not_in",
      "array": ["spam", "banned"]
    }
  ]
}
```

### Boolean Filter

[](#boolean-filter)

```
{
  "filters": [
    {
      "field": "is_active",
      "operator": "=",
      "boolean": true
    },
    {
      "field": "is_verified",
      "operator": "!=",
      "boolean": false
    }
  ]
}
```

### Null Filter

[](#null-filter)

```
{
  "filters": [
    {
      "field": "deleted_at",
      "operator": "is_null"
    },
    {
      "field": "deleted_at",
      "operator": "is_not_null"
    }
  ]
}
```

### Range Filter

[](#range-filter)

```
{
  "filters": [
    {
      "field": "price",
      "operator": "between",
      "min": 100,
      "max": 500
    }
  ]
}
```

### Relation Filter

[](#relation-filter)

```
{
  "filters": [
    {
      "relation": "profile",
      "field": "profile.bio",
      "operator": "=",
      "relatedColumn": "bio",
      "value": "Developer"
    },
    {
      "relation": "profile",
      "field": "profile.phone",
      "operator": "like",
      "relatedColumn": "phone",
      "value": "123%"
    }
  ]
}
```

Available Filters
-----------------

[](#available-filters)

The package supports the following types of filters:

- **DateFilter**: Filters based on dates.
- **NumericFilter**: Filters based on numeric values.
- **StringFilter**: Filters based on string values.
- **ArrayFilter**: Filters based on arrays.
- **BooleanFilter**: Filters based on boolean values.
- **NullFilter**: Filters based on null values.
- **RangeFilter**: Filters based on numeric ranges.
- **RelationFilter**: Filters based on relationships between models.

Getting Filter Operator Translations
------------------------------------

[](#getting-filter-operator-translations)

You can use the FilterService to get the translations of the available filter operators. This is useful for displaying friendly operator names to the end users on the frontend.

### Example

[](#example-1)

```
use Filters;

$translations = Filters::getFilterOperatorsTranslations();

return response()->json($translations);
```

### Custom Filters

[](#custom-filters)

You can also create custom filters by implementing the FilterInterface. Here is an example:

```
namespace App\Filters;

use InovantiBank\AdvancedQueryFilters\Services\Interfaces\FilterInterface;
use Illuminate\Database\Eloquent\Builder;

class CustomFilter implements FilterInterface
{
    public function apply(Builder $query, $value)
    {
        // Custom filter logic
    }
}
```

Registering Custom Filters
--------------------------

[](#registering-custom-filters)

```
Filters::registerFilter('custom_field', \App\Filters\CustomFilter::class);
```

*All types of operators are available in `FilterOperatorEnum`*

```
case DYNAMIC = '';
case EQUAL = '=';
case LESS_THAN = '';
case LESS_THAN_OR_EQUAL = '=';
case NOT_EQUAL = '';
case LIKE = 'like';
case NOT_LIKE = 'not like';
case IN = 'in';
case NOT_IN = 'not in';
case BETWEEN = 'between';
```

Registering Custom Filters
--------------------------

[](#registering-custom-filters-1)

Once you have created a custom filter, you can register it with the `FilterService`:

```
Filters::registerFilter('custom_field', \App\Filters\CustomFilter::class);
```

Testing
-------

[](#testing)

The package comes with unit and feature tests to ensure everything works as expected. You can run the tests using PHPUnit:

```
vendor/bin/phpunit
```

### To run unit tests:

[](#to-run-unit-tests)

```
vendor/bin/phpunit tests/Unit
```

### To run feature tests:

[](#to-run-feature-tests)

```
vendor/bin/phpunit tests/Feature
```

Contribution
------------

[](#contribution)

Feel free to contribute to this package by submitting pull requests or opening issues. We appreciate your feedback and help in improving the package.

- Fork the repository.
- Create a new branch.
- Submit a pull request.

License
-------

[](#license)

This package is open-source software licensed under the [MIT license](https://github.com/Inovanti-Bank/rsa-validator/tree/production?tab=MIT-1-ov-file).

---

Thank you for using Inovanti Advanced Query Filters! If you have any questions or need further assistance, please don't hesitate to reach out [dev@inovanti.com.br](dev@inovanti.com.br)

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance41

Moderate activity, may be stable

Popularity6

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity54

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

Total

2

Last Release

492d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5fddebec36cd271b185d7e5b6fbc6ccdc4663c443238d7d8549fa267835d55b7?d=identicon)[jorgekania](/maintainers/jorgekania)

---

Top Contributors

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

---

Tags

laraveleloquentqueryfiltersadvanced-filters

###  Code Quality

TestsPHPUnit

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/inovanti-bank-inovanti-advanced-query-filters/health.svg)

```
[![Health](https://phpackages.com/badges/inovanti-bank-inovanti-advanced-query-filters/health.svg)](https://phpackages.com/packages/inovanti-bank-inovanti-advanced-query-filters)
```

###  Alternatives

[anourvalar/eloquent-serialize

Laravel Query Builder (Eloquent) serialization

11320.2M21](/packages/anourvalar-eloquent-serialize)[cerbero/query-filters

Filter Laravel Eloquent models based on query parameters.

85282.6k](/packages/cerbero-query-filters)[supliu/laravel-query-monitor

Laravel Query Monitor

287111.9k](/packages/supliu-laravel-query-monitor)[aldemeery/sieve

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

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

Filter for Laravel Eloquent queries, with support for modular filter building

8973.0k3](/packages/czim-laravel-filter)

PHPackages © 2026

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