In this episode, we wrap things up by diving into our OrderIndexController
to fetch and display a list of orders. We make use of the label method we set up earlier on our enum to show the order statuses in a clean way, without any extra fuss in the view.
After rendering out the orders using the enum's label, we take a look at the label function itself for a bit of quick refactoring. Since we're dealing with string-backed enums, we realize that our label method can be dramatically simplified — just a simple call to ucfirst()
on the enum's value does the trick. If we had integer-backed enums, it would be a different story, but in this case, the refactor is straightforward and makes the code that little bit neater.
All in all, it's a short and sweet cleanup to make our enum-driven UI even easier to maintain!