🔴 Laravel
Intermediate
What is the Pipeline pattern in Laravel?
Answer
Laravel's Pipeline passes a subject through a series of "pipes" (classes or closures), each transforming the subject or short-circuiting the chain. It is the mechanism behind middleware. The Pipeline class: app(Pipeline::class)->send($user)->through([ValidateAge::class, HashPassword::class, LogCreation::class])->thenReturn(). Each pipe class implements a handle($passable, $next)` method — call `$next($passable) to pass to the next pipe or return early to short-circuit. Use cases: multi-step form processing, data transformation pipelines, middleware outside the HTTP layer, and complex validation chains. The thenReturn() method returns the final result; then($callback) passes the result to a closure.