Laravel Packages

Supercharged pipelines for Laravel

Published
Supercharged pipelines for Laravel image

The chefhasteeth/pipeline package for Laravel adds a few unique features to the built-in pipeline functionality. For example, this package has a withTransaction() method, which will run this pipeline within a database transaction and automatically commit (or roll back) depending on if the pipeline succeeded:

use Chefhasteeth\Pipeline\Pipeline;
 
 
// i.e., controller method
public function store(StoreRegistrationRequest $request)
{
return Pipeline::make()
->withTransaction()
->send($request->all())
->through([
RegisterUser::class,
AddMemberToTeam::class,
SendWelcomeEmail::class,
])
->then(fn ($data) => UserResource::make($data));
}

Next, this package also has a Pipable trait that you could implement on a data object or class:

use Chefhasteeth\Pipeline\Pipable;
 
class UserDataObject
{
use Pipable;
 
public string $name;
public string $email;
public string $password;
// ...
}
 
// Run the pipeline
return UserDataObject::fromRequest($request)
->pipeThrough([
RegisterUser::class,
AddMemberToTeam::class,
SendWelcomeEmail::class,
])
->then(fn ($data) => UserResource::make($data));

You can learn about this package, get full installation instructions, and view the source code on GitHub. If you'd like to learn more about pipelines in Laravel, Jeff Ochoa wrote Understanding Laravel Pipelines, which is an excellent resource.

Paul Redmond photo

Staff writer at Laravel News. Full stack web developer and author.

Sponsored

tinkerwell logo
Tinkerwell

Enjoy coding and debugging in an editor designed for fast feedback and quick iterations. It's like a shell for your application – but with multi-line editing, code completion, and more.

Visit Tinkerwell

The latest

View all →
CPX: The Composer Package Executor for PHP image

CPX: The Composer Package Executor for PHP

Read article
Laravel AI SDK Adds Human-in-the-Loop Tool Approval image

Laravel AI SDK Adds Human-in-the-Loop Tool Approval

Read article
Pest 5 Released With Test Impact Analysis, Agent Verification, and Evals image

Pest 5 Released With Test Impact Analysis, Agent Verification, and Evals

Read article
Queue-SQL: Run Mass Deletes and Updates Across Parallel Queue Jobs image

Queue-SQL: Run Mass Deletes and Updates Across Parallel Queue Jobs

Read article
Blade Formatting in Laravel Pint image

Blade Formatting in Laravel Pint

Read article
Inertia DevTools Is Now on the Chrome Web Store image

Inertia DevTools Is Now on the Chrome Web Store

Read article