In this episode, we tackle the cluttered if statements in our Blade template that check an order's status and output a label for it. Instead of having all that logic directly in the template, we refactor the code to use a Presenter class called OrderPresenter
. This helps keep our view clean and makes the logic way easier to manage (and reuse, if needed).
First, we set up the presenters folder, create the OrderPresenter
class, and wire it to accept an order. We then move over the status-checking logic from Blade into a new status()
method in the presenter. At first, we implement it with if statements—just like before—but now all the logic lives in PHP rather than the view.
After making sure everything still works, we take it a step further and modernize the method using PHP's match
statement. This makes the code even cleaner and easier to expand in the future. With this update, our templates only have to call order.presenter().status()
, and all the messy conditional logic is gone.
Overall, this episode is all about cleaning up our code by using presenters and modern features in PHP. You'll see how much easier it is to maintain (and read) your views when you separate the presentation logic like this!