💡There’s a concept in Laravel called Pipelines or Pipes.
You can chunk larger tasks into smaller parts in a nice composable way.
🧵Keep reading
1/6
This is how the end result looks like. You can send the content through these pipes. Each of them will modify the content and return the new content:
2/6
Each of those pipes is a simple class with a handle method that is similar to a middleware:
3/6
It’s really simple:
- It takes the content
- Modifies it in some way
- Calls the $next closure which is the next pipe
4/6
If you don’t want to use the default handle method name you can override it and tell Laravel to use your custom method name, for example, ‘execute’:
5/6
What are the benefits?
- You can chunk a larger task into smaller parts in a nice composable way.
- It feels more functional / declarative, if you’re into that.
- The order of the tasks is defined in a small array instead of 100 lines of code.
6/6
Thank you for reading this!
If you liked this thread, you should follow @mmartin_joo
• • •
Missing some Tweet in this thread? You can try to
force a refresh