laravel 管道模式的应用
废话不多说 直接上代码
public function index2(){ $pipe1 = function ($payload, \Closure $next) { $payload = $payload + 1; return $next($payload); }; $pipe2 = function ($payload, \Closure $next) { $payload = $payload * 3; return $next($payload); }; // $data = $request->input('data', 0); $data = 0; $pipeline = new Pipeline(); return $pipeline ->send($data) ->through([$pipe1, $pipe2]) ->then(function ($data) { return $data; }); }