PHPackages                             l3aro/pipeline-query-collection - 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. l3aro/pipeline-query-collection

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

l3aro/pipeline-query-collection
===============================

A query database collection for use with Laravel Pipeline

v1.6.0(4mo ago)21320.4k↓80.8%12MITPHPPHP ^8.1CI failing

Since May 25Pushed 4mo ago3 watchersCompare

[ Source](https://github.com/l3aro/pipeline-query-collection)[ Packagist](https://packagist.org/packages/l3aro/pipeline-query-collection)[ Docs](https://github.com/l3aro/pipeline-query-collection)[ RSS](/packages/l3aro-pipeline-query-collection/feed)WikiDiscussions main Synced today

READMEChangelog (10)Dependencies (18)Versions (33)Used By (0)

A query database collection for use with Laravel Pipeline
---------------------------------------------------------

[](#a-query-database-collection-for-use-with-laravel-pipeline)

[![Latest Version on Packagist](https://camo.githubusercontent.com/c284ccee6c300635924f3ce21107d43b568771d9c0686c5d9a17e933cb11c9c0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6c3361726f2f706970656c696e652d71756572792d636f6c6c656374696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/l3aro/pipeline-query-collection)[![GitHub Tests Action Status](https://camo.githubusercontent.com/d82ac8314a34d59fcb807590ecbce823afd6ff05e23eb48008aa5cfc16b36846/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f6c3361726f2f706970656c696e652d71756572792d636f6c6c656374696f6e2f72756e2d74657374733f6c6162656c3d7465737473)](https://github.com/l3aro/pipeline-query-collection/actions?query=workflow%3Arun-tests+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/1969fc0d820f62645f44b8e565ed12174dd6b5167cfdfffb69c460df4d0cdc18/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6c3361726f2f706970656c696e652d71756572792d636f6c6c656374696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/l3aro/pipeline-query-collection)

This package contains a collection of class that can be used with Laravel Pipeline. Let's see below queries:

```
// users?name=Baro&is_admin=1&created_at_from=2022-06-01&created_at_to=2022-06-31
$users = User::query()
    ->when($request->name ?? null, function($query, $name) {
        $query->where('name', 'like', "%$name%");
    })
    ->when($request->is_admin ?? null, function($query, $isAdmin) {
        $query->where('is_admin', $isAdmin ? 1 : 0);
    })
    ->when($request->created_at_from ?? null, function($query, $date) {
        $query->where('created_at', '>=', $date);
    })
    ->when($request->created_at_to ?? null, function($query, $date) {
        $query->where('created_at', 'filter([
    PipelineQueryCollection\RelativeFilter::make('name'),
    PipelineQueryCollection\BooleanFilter::make('is_admin'),
    PipelineQueryCollection\DateFromFilter::make('created_at'),
    PipelineQueryCollection\DateToFilter::make('created_at'),
])
->get();
```

Table of Contents
-----------------

[](#table-of-contents)

- [A query database collection for use with Laravel Pipeline](#a-query-database-collection-for-use-with-laravel-pipeline)
- [Table of Contents](#table-of-contents)
- [Installation](#installation)
- [Usage](#usage)
    - [Preparing your model](#preparing-your-model)
    - [Feature](#feature)
        - [Bitwise filter](#bitwise-filter)
        - [Boolean filter](#boolean-filter)
        - [Date From filter](#date-from-filter)
        - [Range Filter](#range-filter)
        - [Date To filter](#date-to-filter)
        - [Exact filter](#exact-filter)
        - [Relation filter](#relation-filter)
        - [Relative filter](#relative-filter)
        - [Scope filter](#scope-filter)
        - [Trash filter](#trash-filter)
        - [Sort](#sort)
    - [Detector](#detector)
    - [Custom search column](#custom-search-column)
    - [Custom search value](#custom-search-value)
    - [Extend filter](#extend-filter)
- [Testing](#testing)
- [Contributing](#contributing)
- [Security Vulnerabilities](#security-vulnerabilities)
- [Credits](#credits)
- [License](#license)

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

[](#installation)

Install the package via composer:

```
composer require l3aro/pipeline-query-collection
```

Optionally, you can publish the config file with:

```
php artisan vendor:publish --tag="pipeline-query-collection-config"
```

This is the contents of the published config file:

```
return [
    // key to detect param to filter
    'detect_key' => env('PIPELINE_QUERY_COLLECTION_DETECT_KEY', ''),

    // type of postfix for date filters
    'date_from_postfix' => env('PIPELINE_QUERY_COLLECTION_DATE_FROM_POSTFIX', 'from'),
    'date_to_postfix' => env('PIPELINE_QUERY_COLLECTION_DATE_TO_POSTFIX', 'to'),

    // default motion for date filters
    'date_motion' => env('PIPELINE_QUERY_COLLECTION_DATE_MOTION', 'find'),
];
```

Usage
-----

[](#usage)

### Preparing your model

[](#preparing-your-model)

To use this collection with a model, you should implement the following interface and trait:

```
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Baro\PipelineQueryCollection\Concerns\Filterable;
use Baro\PipelineQueryCollection\Contracts\CanFilterContract;

class YourModel extends Model implements CanFilterContract
{
    use Filterable;

    public function getFilters(): array
    {
        return [
            // the filter and sorting that your model need
        ];
    }
}
```

After setup your model, you can use scope filter on your model like this

```
YourModel::query()->filter()->get();
```

You can also override the predefined filter lists in your model like this

```
YourModel::query()->filter([
    // the custom filter and sorting that your model need
])
->paginate();
```

### Feature

[](#feature)

Here the use all filter and sort in the collection

#### Bitwise filter

[](#bitwise-filter)

```
use Baro\PipelineQueryCollection\BitwiseFilter;

// users?permission[0]=2&permission[1]=4
User::query()->filter([
    BitwiseFilter::make('permission'), // where permission & 6 = 6
]);
```

#### Boolean filter

[](#boolean-filter)

```
use Baro\PipelineQueryCollection\BooleanFilter;

// users?is_admin=1
User::query()->filter([
    BooleanFilter::make('is_admin'), // where is_admin = 1
]);
```

#### Date From filter

[](#date-from-filter)

```
use Baro\PipelineQueryCollection\DateFromFilter;
use Baro\PipelineQueryCollection\Enums\MotionEnum;

// users?updated_at_from=2022-05-31
User::query()->filter([
    DateFromFilter::make('updated_at'), // where updated_at >= 2022-05-31
    DateFromFilter::make('updated_at', MotionEnum::TILL), // where updated_at > 2022-05-31
    // you can config default motion behavior and the postfix `from` in the config file
]);
```

#### Date To filter

[](#date-to-filter)

```
use Baro\PipelineQueryCollection\DateToFilter;
use Baro\PipelineQueryCollection\Enums\MotionEnum;

// users?updated_at_to=2022-05-31
User::query()->filter([
    DateToFilter::make('updated_at'), // where updated_at filter([
    RangeFromFilter::make('price'), // Adds where price >= 100
    RangeToFilter::make('price'),   // Adds where price filter([
    RangeFromFilter::make('age')->setPostFix('min'), // Adds where age >= 18
    RangeToFilter::make('age')->setPostFix('max'),   // Adds where age filter([
    ExactFilter::make('id'), // where id = 4
]);
```

#### Relation filter

[](#relation-filter)

```
use Baro\PipelineQueryCollection\RelationFilter;

// users?roles_id[0]=1&roles_id[1]=4
User::query()->filter([
    RelationFilter::make('roles', 'id'), // where roles.id in(1,4)
]);
```

#### Relative filter

[](#relative-filter)

```
use Baro\PipelineQueryCollection\RelativeFilter;
use Baro\PipelineQueryCollection\Enums\WildcardPositionEnum;

// users?name=Baro
User::query()->filter([
    RelativeFilter::make('name'), // where('name', 'like', "%Baro%")
    RelativeFilter::make('name', WildcardPositionEnum::LEFT), // where('name', 'like', "%Baro")
    RelativeFilter::make('name', WildcardPositionEnum::RIGHT), // where('name', 'like', "Baro%")
]);
```

You can also filter multiple columns at once

```
use Baro\PipelineQueryCollection\FieldsRelativeFilter;
use Baro\PipelineQueryCollection\Enums\WildcardPositionEnum;

// users?search=Baro
User::query()->filter([
    FieldsRelativeFilter::make('search', ['name', 'title']), //  where ("name" like '%Baro%' or "title" like '%Baro%')
]);
```

#### Scope filter

[](#scope-filter)

```
// users?search=Baro

// User.php
public function scopeSearch(Builder $query, string $keyword)
{
    return $query->where(function (Builder $query)  use ($keyword) {
        $query->where('id', $keyword)
            ->orWhere('name', 'like', "%{$keyword}%");
    });
}

// Query
use Baro\PipelineQueryCollection\ScopeFilter;

User::query()->filter([
    ScopeFilter::make('search'), // where (`id` = 'Baro' or `name` like '%Baro%')
]);
```

#### Trash filter

[](#trash-filter)

When using Laravel's [soft delete](https://laravel.com/docs/master/eloquent#querying-soft-deleted-models), you can use the pipe `TrashFilter`to query these models. The default query name is `trashed`, and filters responds to particular values:

- `with`: the query should be `?trashed=with` to include soft deleted records to the result set
- `only`: the query should be `?trashed=only` to return only soft deleted records to the result set
- any other value, or completely remove `trashed` from request query will return only records that are not soft deleted in the result set

You can change query name `trashed` by passing your custom name to the `TrashFilter` constructor

```
use Baro\PipelineQueryCollection\TrashFilter;

// ?removed=only
User::query()->filter([
   TrashFilter::make('removed'), // where `deleted_at` is not null
]);
```

#### Sort

[](#sort)

```
use Baro\PipelineQueryCollection\ScopeFilter;

// users?sort[name]=asc&sort[permission]=desc
User::query()->filter([
    Sort::make(), //  order by `name` asc, `permission` desc
]);
```

### Detector

[](#detector)

Sometimes, you want to setup your request with a prefix like `filter.`. You can config every pipe that have it

```
use Baro\PipelineQueryCollection\ExactFilter;

// users?filter[id]=4&filter[permission][0]=1&filter[permission][1]=4
User::query()->filter([
    ExactFilter::make('id')->detectBy('filter.'), // where id = 4
    BitwiseFilter::make('permission')->detectBy('filter.'), // where permission & 5 = 5
]);
```

Or, you can define it globally

```
// users?filter[id]=4&filter[permission][0]=1&filter[permission][1]=4

// .env
PIPELINE_QUERY_COLLECTION_DETECT_KEY="filter."

// Query
User::query()->filter([
    ExactFilter::make('id'), // where id = 4
    BitwiseFilter::make('permission'), // where permission & 5 = 5
]);
```

### Custom search column

[](#custom-search-column)

Sometimes, your request field is not the same with column name. For example, in your database you have column `respond` and want to perform some query against it, but for some reasons, your request query is `reply` instead of `respond`.

```
// users?reply=baro

User::query()->filter([
    RelativeFilter::make('reply')->filterOn('respond'), // where respond like '%baro%'
]);
```

### Custom search value

[](#custom-search-value)

Your value that need to be searched isn't from your request? No problems. You can use `value()` function to hard set the search value!

```
User::query()->filter([
    RelativeFilter::make('name')->value('Baro'), // where('name', 'like', "%Baro%")
]);
```

### Extend filter

[](#extend-filter)

Yeah, you are free to use your own pipe. Take a look at some of my filters. All of them extends `BaseFilter` to have some useful properties and functions.

Testing
-------

[](#testing)

```
composer test
```

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

[](#contributing)

Please see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [l3aro](https://github.com/l3aro)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

55

—

FairBetter than 97% of packages

Maintenance76

Regular maintenance activity

Popularity44

Moderate usage in the ecosystem

Community19

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor1

Top contributor holds 74.6% 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 ~53 days

Recently: every ~214 days

Total

27

Last Release

128d ago

Major Versions

v0.1.4 → v1.0.02022-05-25

### Community

Maintainers

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

---

Top Contributors

[![l3aro](https://avatars.githubusercontent.com/u/25253808?v=4)](https://github.com/l3aro "l3aro (103 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (12 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (8 commits)")[![laravel-shift](https://avatars.githubusercontent.com/u/15991828?v=4)](https://github.com/laravel-shift "laravel-shift (6 commits)")[![michaelkonstantinou](https://avatars.githubusercontent.com/u/55360694?v=4)](https://github.com/michaelkonstantinou "michaelkonstantinou (5 commits)")[![karimalihussein](https://avatars.githubusercontent.com/u/65453298?v=4)](https://github.com/karimalihussein "karimalihussein (2 commits)")[![s-patompong](https://avatars.githubusercontent.com/u/3887531?v=4)](https://github.com/s-patompong "s-patompong (1 commits)")[![DeivisFelipe](https://avatars.githubusercontent.com/u/36674115?v=4)](https://github.com/DeivisFelipe "DeivisFelipe (1 commits)")

---

Tags

laravell3aropipeline-query-collection

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/l3aro-pipeline-query-collection/health.svg)

```
[![Health](https://phpackages.com/badges/l3aro-pipeline-query-collection/health.svg)](https://phpackages.com/packages/l3aro-pipeline-query-collection)
```

###  Alternatives

[spatie/laravel-pdf

Create PDFs in Laravel apps

1.0k4.8M47](/packages/spatie-laravel-pdf)[dedoc/scramble

Automatic generation of API documentation for Laravel applications.

2.1k11.2M102](/packages/dedoc-scramble)[wnx/laravel-backup-restore

A package to restore database backups made with spatie/laravel-backup.

213421.5k2](/packages/wnx-laravel-backup-restore)[spatie/laravel-passkeys

Use passkeys in your Laravel app

471890.7k39](/packages/spatie-laravel-passkeys)[rawilk/profile-filament-plugin

Profile &amp; MFA starter kit for filament.

3914.6k](/packages/rawilk-profile-filament-plugin)[lacodix/laravel-model-filter

A Laravel package to filter, search and sort models with ease while fetching from database.

17558.6k](/packages/lacodix-laravel-model-filter)

PHPackages © 2026

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