Laravel: The hidden Pipeline [Part 2]

Serialized content processing, meet your new friend: the Pipeline.

Photo by Erlend Ekseth on Unsplash

Pipes

Handling the data

public function handle($passable, Closure $next)
{
// Your logic
}
public function handle($passable, Closure $next)
{
$passable = ucfirst($passable);
}
public function handle($passable, Closure $next)
{
$passable = ucfirst($passable);
return $next($passable);
}

Jumping to the end

public function handle($passable, Closure $next)
{
$result = $next($passable);
// Do something with the result return $result;
}

Magic of pipe arguments

$result = app(\Illuminate\Pipeline\Pipeline::class)
->send(’this should be correctly formatted’)
->through([
// ...
'App\Strings\Pipes\RemoveWords:should,formatted'
])->thenReturn();
echo $result; // "this be correctly"
/**
* Removes a list of words
*
* @param string $string
* @param Closure $next
* @param array $remove
* @return string
*/
public function handle($string, Closure $next, ...$remove)
{
return $next(str_replace($remove, '', $string));
}
$result = app(\Illuminate\Pipeline\Pipeline::class)
->send('this should be correctly formatted')
->through([
// ...
'replacer:should,formatted'
]);
Route::get('podcast/{podcast}', 'PodcastController@show')
->middleware('auth:api');

A word of advice with Responses

return $response instanceof Responsable 
? $response->toResponse($this->getContainer()->make(Request::class))
: $response;

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Italo Baeza Cabrera

Graphic Designer graduate. Full Stack Web Developer. Retired Tech & Gaming Editor. https://italobc.com