Laravel Enhanced Pipeline is a package that offers Laravel pipelines with DB transaction support and handy additional methods.
Installation
You can install this package using composer:
composer require michael-rubel/laravel-enhanced-pipeline
Usage
Import modified pipeline to your class:
use MichaelRubel\EnhancedPipeline\Pipeline;
Then you can make the pipeline:
Pipeline::make()
->withTransaction()
->send($data)
->through([
// your pipes
])
->onFailure(function ($data, $exception, $pipe) {
// do something when exception caught
return $data;
})->then(function ($data) {
// do something when all pipes completed their work
return $data;
});
You can as well instantiate the pipeline using IoC or manually:
app(Pipeline::class)
...
(new Pipeline(app()))
...
(new Pipeline)
->setContainer(app())
...
If you want to override the original Pipeline resolved through IoC Container, you can add binding in the ServiceProvider register method:
$this->app->singleton(\Illuminate\Pipeline\Pipeline::class, \MichaelRubel\EnhancedPipeline\Pipeline::class);
For more details, you can visit its documentation and source code on Github.