Payment is more than just payment
Laravel-workflow
In this article, we'll learn how Laravel Workflow can simplify and manage our workflows, making them easier to understand. We'll also look at the main idea behind the package.

Intro:
First, let's clarify that "payment" is just an example here. The idea is that some features are built from multiple actions. As the project grows, understanding the inputs and outputs of a feature becomes increasingly challenging.
Understanding the code often requires more than just reading it. You need a good grasp of the framework, including components like events, listeners, and observers. Additionally, navigating through the code from file to file can be challenging, especially when there’s no documentation available, which is quite common, and this can leave you feeling lost and unsupported.
A ~week ago, Povilas Korop made a LinkedIn post about the same subject.
Povilas here discusses how respecting SOLID principles, especially the separation of concerns, and clean code rules can complicate even a simple task, which is why he prefers 'longer' or 'fat' controller methods.
Working with legacy code full of hidden logic has made me think how we can follow SOLID principles, keep our code clean, and stick to framework best practices without getting lost!
I need one place where I can encapsulate the entire feature so that a junior or newly hired developer can see this class and understand everything about it, at the same time without violating these principles.
That’s the idea behind Laravel Workflow to bundle all the details of a workflow into one class, where you can find everything related to that feature.
- The actions chain with their state, knowing which actions failed or succeeded.
- The hidden logic, like observers, where you can register them from inside the workflow class itself.
- Standard responses.
- Event tracking to understand what happened during the workflow execution.
- I will add more 🚀
Demo Time:
Now, let's see a simple demo:
Let's start by installing the package via Composer:
First, we need to generate a workflow class using this artisan command:
We will also need some action classes. Additionally, we can use Artisan to execute:
Our workflow class will be structured as follows:
They will be executed before our main action and are useful for tasks like validation, data preparation, and so on..
We will simulate the payment logic in the MakePayment class, which serves as the main action in the chain.
SendEmails is a typical Laravel job that will be dispatched after all preceding actions have successfully completed. It handles tasks such as sending email notifications related to the completed payment process.
Now our checkout can be something like this:
Here, we execute our PaymentWorkflow, which processes all actions and determines whether the workflow completed successfully or encountered any issues.
In closing, I think this demo has reached its end, and I want to thank you for reading. I hope you learned something from it!
✨ I also want to point out that the package is fairly new, and I’m excited to hear your feedback! Your thoughts will not only inspire me but also help shape future versions of the package.
If you want to contact me, you can reach me on LinkedIn || Twitter || Github!.
I welcome you to reach out and say hello. Meeting new people and expanding my network is something I always look forward to! 😊