Mahmoud Al-HabashOpen to new projects
  • WorkWork
  • ServicesServices
  • LabLab
  • WritingWriting
  • ContactContact
Amman--:--عربي
Writing/Laravel

Laravel Pipelines: Chain Operations Elegantly

Use Laravel pipelines to chain complex operations cleanly.

16 January 20261 min readLaravelاقرأ بالعربية

On this page

  1. Basic Pipeline
  2. Pipe Class
  3. Custom Method

Chain operations with pipelines:

Basic Pipeline

php
$result = app(Pipeline::class)
    ->send($order)
    ->through([
        ValidateOrder::class,
        ApplyDiscount::class,
        CalculateTax::class,
        ProcessPayment::class,
    ])
    ->thenReturn();

Pipe Class

php
class ApplyDiscount
{
    public function handle($order, Closure $next)
    {
        $order->applyDiscount();
        return $next($order);
    }
}

Custom Method

->via('process')
->through([...]);
All articles

Keep reading

  • Laravel Action Classes Pattern16 January 20261 min read
  • Laravel Action Classes: Single Responsibility16 January 20261 min read
  • Laravel API Rate Limiting16 January 20261 min read