illuminate/pipeline
Illuminate Pipeline provides a simple, fluent way to send an object through a series of pipes (closures or classes) in Laravel. Build customizable middleware-style workflows, transform data step by step, and control the final destination with clean, composable code.
Start by requiring the package: composer require illuminate/pipeline. If you're in a Laravel app, it's already included—no extra setup needed. For standalone projects, bootstrap a simple pipeline with send($value)->through([...pipes])->thenReturn(). A first use case: chain validation and normalization steps for incoming API data—e.g., cast types, validate required fields, and transform dates—without bloating controllers.
$next($payload).ApplyDiscount → ValidateStock → ReserveInventory → SendConfirmation. Pipes stay small, testable, and composable.send($payload)->through(['App\Pipes\ValidateEmail', ValidatePhone::class])->resolveUsing(app())→thenReturn(). Ideal when pipes depend on services (e.g., repositories, mailers).ValidationPipeline, AuditPipeline) and parametrize them—e.g., inject rules or callbacks—to reuse across handlers, jobs, and console commands.then() to run final aggregation logic (e.g., summarizing pipeline results), or use pipe() to return the instance for deferred execution.return $payload, the next stage receives null. Always explicitly return the payload—even if unmodified—to avoid subtle bugs.clone $order) when idempotency matters (e.g., retries, dry-runs).thenReturn() in try/catch, or add a final pipe that logs errors and returns a fallback.handle($payload, callable $next) methods for easy mocking and assertion.isAuthenticated, isValidInput) before expensive operations (DB queries, external API calls).Pipeline to inject tracing (e.g., timings per pipe), circuit breakers, or context-aware fallbacks—override handlePipe() to intercept pipe execution.->pipe(fn ($payload) => dump("Step X: ", $payload)) sparingly; better yet, log payload snapshots with context via a dedicated debug pipe.How can I help you explore Laravel packages today?