What is the Pipeline pattern in Laravel?
Why Interviewers Ask This
This question targets practical, hands-on experience with Laravel. Interviewers want to see if you've worked with these concepts in real projects, not just read about them. Strong answers include concrete examples.
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.
Common Mistake
Many candidates answer correctly but can't explain the 'why'. Always be prepared to justify your answer with a concrete example or use case from your Laravel experience.