PHPackages                             vati/filtero - 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. vati/filtero

ActiveLibrary

vati/filtero
============

A Laravel package to filter, search, sort data from models and their relations

v1.0.3(1y ago)18MITPHPPHP ^7.4|^8.0

Since Jun 7Pushed 1y ago1 watchersCompare

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

READMEChangelog (1)Dependencies (2)Versions (5)Used By (0)

Filtero
=======

[](#filtero)

Filtero is a Laravel package that provides a convenient way to filter, search, and sort data from models and their relationships. You only have to provide request query params properly, and Filtero will handle the rest for you.

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

[](#installation)

You can install the package via composer:

```
composer require vati/filtero
```

Usage
-----

[](#usage)

1. **Include FilterTrait in your Model**: Use the provided `FilterTrait` trait in your model to enable filtering, searching, and sorting capabilities.

    ```
    use Vati\Filtero\FilterTrait;

    class YourModel extends Model
    {
        use FilterTrait;

        /**
         * The columns that are searchable.
         *
         * @var array
         */
        protected array $searchable = [
            'status',
            [
                'recipient' => [
                    'CONCAT_WS(" ", first_name, last_name)'
                ],
                'currency' => [
                    'code'
                ]
            ],
        ];

        /**
         * The columns that are filterable.
         *
         * @var array
         */
        protected array $filterable = [
            'status',
            'currency_id',
            'provider_transaction_id',
            [
                'recipient' => [
                    'country_id',
                    'city',
                    'phone',
                    'email'
                ]
            ],
        ];

       /**
        * The columns that are sortable.
        *
        * @var array
        */
        protected array $sortable = [
            'id',
            'user_id',
            'recipient_id',
            'recipient.first_name', //relation sort
            'payout_id',
            'estimated_provider_fee{sum}estimated_platform_fee', // sum multiple columns, order must be same in http_query
            'payment_amount',
            'total_amount',
            'currency_id',
            'status',
            'reference',
            'created_at'
        ];
    }
    ```
2. **Use in Repository or Controller**: Utilize the filtering, searching, and sorting capabilities in your repository or controller.

    ```
    $payments = YourModel::with(['recipient'])->search()->filter()->sort()->paginate($request->per_page ?? 10);
    ```

Example Query
-------------

[](#example-query)

An example query in your repository or controller would look like:

```
$payments = YourModel::with(['recipient'])
            ->search()
            ->filter()
            ->sort()
            ->paginate($request->per_page ?? 10);
```

If you only want to perform a search without filtering or sorting, you can use `$payment->search()`.

### Api Endpoint Realistic Example

[](#api-endpoint-realistic-example)

Here's a realistic example of how you can use Filtero in your API endpoints:

```
/payment/payments?search=example@example.com&sort=recipient.first_name&status=completed&currency_id=3&currency[code]=CHF&range[created_at][min]=2024-05-22&range[created_at][max]=2024-06-22

```

Request Options
---------------

[](#request-options)

Your request can contain various options for filtering, searching, and sorting:

- **Search**: Use the `search` query parameter to perform a search. Example: `?search=example@example.com`.
- - To search multiple columns as one, like searching for "John Doe" across first\_name and last\_name, use the CONCAT\_WS function in your searchable array.
- **Sort**: Use the `sort` query parameter to specify the sorting column. You can use dot notation for relational sorting. Example: `?sort=recipient.first_name`.
- - Sort by the attribute in descending order: `?sort=-created_at`
    - Let's say you want to sort the results based on the sum of `estimated_provider_fee` and `estimated_platform_fee`, in ascending order. Your request URL would look like this:

        ```
        GET /your/route?sort=estimated_provider_fee{sum}estimated_platform_fee

        ```
- - This will return the results sorted based on the sum of `estimated_provider_fee` and `estimated_platform_fee`.
- - Example query for sum: `?sort=estimated_provider_fee{sum}estimated_platform_fee`
- **Filter**: Use query parameters to filter data based on specific attributes.
- - For Example:
- - - To filter by the `city` attribute in the related `recipient` table: `?recipient[city]=New York`
- - - To filter by the `status` attribute in the main table: `?status=completed`
- **Range**: You can specify a range for date attributes using the `range` query parameter. Example: `?range[created_at][min]=2024-05-22&range[created_at][max]=2024-06-22`.

Of course! Here's the updated section regarding the range filter:

---

Range Filter
------------

[](#range-filter)

The range filter allows you to specify a range for numeric attributes, in addition to date attributes. This feature provides flexibility in filtering data based on various numeric criteria.

### Usage

[](#usage-1)

To use the range filter:

- Specify the `min` and/or `max` values for the range of the attribute you want to filter.
- Include the range in the request using the `range` query parameter.

### Example

[](#example)

```
// Example request URL
?range[price][min]=10&range[price][max]=100
```

In this example, `price` is a numeric attribute, and the query filters records where the price falls within the range of 10 to 100.

---

Feel free to let me know if there are any more adjustments or additions you'd like!

Configuration
-------------

[](#configuration)

You can configure Filtero by modifying the `config/filtero.php` file. The configuration options include:

- `search_key`: The key used for search queries.
- `sort_key`: The key used for sorting queries.
- `range_key`: The key used for range queries.
- `include_equal_in_range_filter`: Option to include equal values in range filtering.

Publishing Configuration
------------------------

[](#publishing-configuration)

To publish the configuration file, run the following Artisan command:

```
php artisan vendor:publish --provider="Vati\Filtero\FilteroServiceProvider"
```

Credits
-------

[](#credits)

- [Vati Child](https://github.com/vatichild)

License
-------

[](#license)

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

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance31

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity48

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

4

Last Release

708d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/222d211872a6d597f776520d8d88851da9568c45923d5bf8d4f6db213b70c9c2?d=identicon)[vati](/maintainers/vati)

---

Top Contributors

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

### Embed Badge

![Health badge](/badges/vati-filtero/health.svg)

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

###  Alternatives

[laravel/horizon

Dashboard and code-driven configuration for Laravel queues.

4.2k84.2M225](/packages/laravel-horizon)[spatie/laravel-sitemap

Create and generate sitemaps with ease

2.6k14.6M107](/packages/spatie-laravel-sitemap)[spatie/laravel-honeypot

Preventing spam submitted through forms

1.6k6.0M60](/packages/spatie-laravel-honeypot)[laravel-notification-channels/apn

Apple APN Push Notification Channel

2021.9M4](/packages/laravel-notification-channels-apn)[specialtactics/l5-api

Dependencies for the Laravel API Boilerplate package

3672.8k2](/packages/specialtactics-l5-api)[takielias/tablar-kit

The Elegance of Tablar Dashboard

413.4k](/packages/takielias-tablar-kit)

PHPackages © 2026

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