PHPackages                             pedrokeilerbatistarojo/smartfilter - 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. pedrokeilerbatistarojo/smartfilter

ActiveLaravel-package[Search &amp; Filtering](/categories/search)

pedrokeilerbatistarojo/smartfilter
==================================

This Laravel package provides a streamlined solution for filtering and listing data. It accepts an input array, applies customizable filters, and returns a structured JSON response. Ideal for projects requiring dynamic data filtering with minimal setup, the package ensures consistency in API responses while maintaining flexibility to handle complex filter conditions.

v1.0.4(1y ago)36MITPHPPHP ^8.2

Since Dec 5Pushed 1y ago1 watchersCompare

[ Source](https://github.com/pedrokeilerbatistarojo/smartfilter)[ Packagist](https://packagist.org/packages/pedrokeilerbatistarojo/smartfilter)[ RSS](/packages/pedrokeilerbatistarojo-smartfilter/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (7)Versions (7)Used By (0)

SmartFilter
===========

[](#smartfilter)

SmartFilter is a Laravel package designed to provide robust and flexible filtering capabilities for APIs. It allows developers to apply filters, sorting, and pagination to data retrieval seamlessly while returning structured JSON responses.

---

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

[](#installation)

1. **Require the package via Composer:**

    ```
    composer require pedrokeilerbatistarojo/smartfilter
    ```
2. **Publish the configuration (optional):**

    ```
    php artisan vendor:publish --provider="Pedrokeilerbatistarojo\Smartfilter\SmartfilterServiceProvider"
    ```
3. **Usage:** Include the package in your controller or service to start applying filters.

---

Features
--------

[](#features)

- Apply filters with various operators (e.g., `like`, `=`, etc.).
- Select specific columns to retrieve.
- Include relationships for eager loading.
- Sort results by any field.
- Paginate results with customizable parameters.
- Structured JSON responses with metadata.

---

Usage Example
-------------

[](#usage-example)

### Sample Request

[](#sample-request)

```
GET /api/users?filters[0][0]=name&filters[0][1]=like&filters[0][2]=Owner&columns[]=id&columns[]=name&columns[]=email&includes[]=role&sortField=created_at&sortType=asc&itemsPerPage=8&currentPage=1
```

### Query Params

[](#query-params)

```
filters:[["name", "like", "Owner", "and"],["email", "like","owner@example.com", "and"],["name", "like", "Owner", "and", "role"]]
columns:["id", "name", "email"]
includes:["role"]
sortField:created_at
sortType:asc
itemsPerPage:8
currentPage:1

```

### Controller Example

[](#controller-example)

```
use Pedrokeilerbatistarojo\Smartfilter\Services\FilterService;
use Pedrokeilerbatistarojo\Smartfilter\Helpers\ResponseHelper;
use Illuminate\Http\Request;
use App\Models\User;
use Exception;

class UserController extends Controller
{

    public function __construct(
        private readonly FilterService $filterService
    ){
    }

    /**
     * @throws Exception
     */
    public function __invoke(Request $request)
    {
       try {
          $response = $this->filterService->execute(User::class, $request->all());
          return ResponseHelper::sendResponse($response);
       }
       catch(Exception $ex){
          return ResponseHelper::sendError($ex->getMessage());
       }
    }
}
```

### Expected JSON Response

[](#expected-json-response)

```
{
    "success": true,
    "message": "Search completed successfully",
    "errors": null,
    "payload": {
        "items": [
            {
                "id": 1,
                "name": "Owner",
                "email": "owner@example.com"
            },
            {
                "id": 2,
                "name": "Admin",
                "email": "admin@example.com"
            }
        ],
        "metadata": {
            "currentPage": 1,
            "lastPage": 5,
            "itemsPerPage": 8,
            "total": 40
        },
        "total": 40
    }
}
```

---

Testing
-------

[](#testing)

1. **Run the test suite:**

    ```
    php artisan test
    ```
2. **Example Test:**

    ```
    public function test_filter_with_filters(): void
    {
        $filters = [
            ['name', 'like', 'Owner', 'and'],
            ['email', 'like', 'owner@example.com', 'and'],
            ['name', 'like', 'Owner', 'and', 'role']
        ];

        $columns = ['id', 'name', 'email'];
        $includes = ['role'];

        $params = [
            'filters' => $filters,
            'columns' => $columns,
            'includes' => $includes,
            'sortField' => 'created_at',
            'sortType' => 'asc',
            'itemsPerPage' => 8,
            'currentPage' => 1
        ];

        $queryString = http_build_query($params);
        $endpoint = "/api/users?{$queryString}";

        $response = $this->get($endpoint);
        $response->assertStatus(200);
        $response->assertJsonStructure([
            'success',
            'message',
            'errors',
            'payload' => [
                'items' => [
                    '*' => [
                        'id',
                        'name',
                        'email'
                    ]
                ],
                'metadata' => [
                    'currentPage',
                    'lastPage',
                    'itemsPerPage',
                    'total'
                ],
                'total'
            ]
        ]);
    }
    ```

---

Contributing
------------

[](#contributing)

Feel free to fork this repository and submit pull requests. Ensure that all tests pass and maintain code quality standards.

---

License
-------

[](#license)

SmartFilter is open-source software licensed under the [MIT License](LICENSE).

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance39

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity55

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

5

Last Release

521d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/c057a53392bc6b2623b86009d581931f82021b2c8ceab2cb9376d7de6bff0799?d=identicon)[pedrokeilerbatistarojo](/maintainers/pedrokeilerbatistarojo)

---

Top Contributors

[![laravel777crew](https://avatars.githubusercontent.com/u/153053523?v=4)](https://github.com/laravel777crew "laravel777crew (9 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/pedrokeilerbatistarojo-smartfilter/health.svg)

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

###  Alternatives

[laravel/cashier

Laravel Cashier provides an expressive, fluent interface to Stripe's subscription billing services.

2.5k25.9M107](/packages/laravel-cashier)[laravel/scout

Laravel Scout provides a driver based solution to searching your Eloquent models.

1.7k49.4M479](/packages/laravel-scout)[larastan/larastan

Larastan - Discover bugs in your code without running it. A phpstan/phpstan extension for Laravel

6.4k43.5M5.2k](/packages/larastan-larastan)[laravel/passport

Laravel Passport provides OAuth2 server support to Laravel.

3.4k85.0M531](/packages/laravel-passport)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9682.1M97](/packages/roots-acorn)[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)

PHPackages © 2026

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