How to use Pipelines in Livewire – Laravel

The Pipeline Facade is another Helper in Laravel. It provides an appropriate way to ‘pipe’ a specific input through a series of closures, callable, and classes. Let’s go over this example to see how to use pipelines in Livewire.

This gives each class the chance to analyze and change input data and call the next callable present in the pipeline. 

use Closure;

use App\Models\User;

use Illuminate\Support\Facades\Pipeline;

$user = Pipeline::send($user)

           ->through([

               function (User $user, Closure $next) {

                   // ...

                   return $next($user);

               },

               function (User $user, Closure $next) {

                   // ...

                   return $next($user);

               },

           ])

           ->then(fn (User $user) => $user);

The Pipeline facade uses the send function as shown above. 

Leave a Comment