In this episode, we explore a neat new addition to Laravel's pipeline system: the finally()
method. If you've been making use of pipelines (or even if you haven't checked them out yet), you'll see how this new method helps clean up your code and handle tidy-up steps more gracefully.
We walk through an example (borrowed straight from the official pull request!) where we're working with a deployment model that tracks when something is deployed and when it's stopped. Normally, you might need to do a bit of PHP gymnastics with try
and finally
blocks to make sure cleanup happens regardless of success or failure. For example, updating a stopped_at
column even if something blows up in the middle of your pipeline steps.
But now, with the new finally()
method on the pipeline, we can attach a closure that'll always run at the end—no matter what happens in the steps. The video shows both the old PHP approach and the new Laravel way, letting you compare how much cleaner and more "fluent" your code can be.
By the end, you'll see how simple it is to use the new finally()
method: just pop your finalizing logic right on the pipeline and you're done. It's a small but very welcome change if you're building apps and need this kind of reliable cleanup!