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

ActiveLibrary[Search &amp; Filtering](/categories/search)

crazynds/query-pipeline
=======================

A query pipeline for use with custom search in Laravel project.

v1.3.0(1mo ago)01.9kMITPHPPHP ^8.1CI passing

Since Oct 16Pushed 1w ago1 watchersCompare

[ Source](https://github.com/crazynds/LaravelQueryPipeline)[ Packagist](https://packagist.org/packages/crazynds/query-pipeline)[ Docs](https://github.com/crazynds/QueryPipeline-Laravel)[ RSS](/packages/crazynds-query-pipeline/feed)WikiDiscussions main Synced yesterday

READMEChangelog (10)Dependencies (10)Versions (24)Used By (0)

Query Pipeline Description
==========================

[](#query-pipeline-description)

[![Latest Version on Packagist](https://camo.githubusercontent.com/52f3e5f9cc3b56dba914539aaac32ab5be0efd399947d0679f699c8397e03be9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6372617a796e64732f71756572792d706970656c696e652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/crazynds/query-pipeline)[![Total Downloads](https://camo.githubusercontent.com/cad986bfa1f83636c463051a032546d830fdc30569b0bce1d6f90db16dd1af3e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6372617a796e64732f71756572792d706970656c696e652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/crazynds/query-pipeline)

This package contains a collection of class that can be used with Laravel Pipeline.

Can do the same as the package [pipeline-query-collection](https://github.com/l3aro/pipeline-query-collection) however the syntax differs, and gives the user a little more possibilities.

Allows you to implement conditionals for joins and add where clauses if certain data was passed.

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

[](#installation)

You can install the package via composer:

```
composer require crazynds/query-pipeline
```

Usage
-----

[](#usage)

See the example below:

```
use Crazynds\QueryPipeline\Middleware\ILIKEQuery;
use Crazynds\QueryPipeline\Middleware\JoinQuery;
use Crazynds\QueryPipeline\QueryPipeline;

class ClientController extends Controller
{
    use QueryPipeline;

    public function index(Request $request){
        $page = $request->input('page', 1);
        $qtd = $request->input('qtd', 20);
        $query = Client::query();
        $data = $request->all();
        $query = $this->runPipeline($query,$data,[
            JoinQuery::class => [
                //table to join
                'addresses' => [
                    'on' => [ // required
                        'clients.address_id',
                        '=',
                        'addresses.id',
                    ],
                    'checkParameters'=>[ // optional, if any items from this array exist in the data keys, the join will be added to the query
                        // if not passed checkParameters, the join will be added in any condition
                        'country',
                        'state',
                        'city',
                    ],
                ]
            ],
            ILIKEQuery::class => [
                //table name
                'clients'=>[
                    //columns
                    'name',
                    'code',
                    'email',
                ],
                'addresses'=>[
                    'country',
                    'state',
                    'city',
                ]
            ],
        ]);
        return $query->paginate($qtd);
    }
}
```

### Steps

[](#steps)

1. First add the trait QueryPipeline from Crazynds\\QueryPipeline\\QueryPipeline to your class.
2. Setup your middleware stack variable
3. Send the base query, your data values and your stack to $this-&gt;runPipeline and the query pipeline will run.
4. Be happy :&gt;

Middlewares
-----------

[](#middlewares)

A middleware in this context means a step in which the query will be processed. See all the middlewares in folder src/middleware.

Each middleware has your stack of parameters, see below the specifications:

### Join Query

[](#join-query)

The join query middleware add a join query based on conditions passed as parameters. Each join query can include multiples joins.

The base object recived by each iten in array is represented below:

```
