Menu

1 / 2

Laravel Pipeline Class: Multi-Step Flows Explained

DEV Community: laravel·devTalk·1 day ago
#X77MkSmg
#devtolaravel#devto#dev#pipeline#steps
Reading 0:00
15s threshold

Every request to your Laravel app travels through a stack of middleware: each one does some work, then hands the request to the next. The class that makes this happen is not private to the framework. It is Illuminate\Pipeline\Pipeline , and you can send anything through it: an order during checkout, a row from a CSV import, a text that needs cleaning. This article explains how it works in plain terms, with two examples I ran against Laravel 13.35.0 and a real database, including one where it saves you from a half-finished order.

The idea in one minute

Think of an assembly line. You put an object on the belt, and a list of stations each do one job on it. A station is a class with a handle() method. It receives the object and a $next closure. When it finishes its job, it passes the object on by calling $next :

use Closure ;

class TrimStrings { public function handle ( array $row , Closure $next ) { return $next ( array_map ( fn ( $value ) => is_string ( $value ) ?…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.