In this episode, we do a quick recap on why and how we've used enums in our Laravel app, rather than just plain strings or setting enum constraints directly in the database.
We started by defining an enum inside our application to represent order statuses. This helped us validate the data more reliably, since we could check that any status being saved matched one of our predefined enum cases. We used these enum values both on the create and edit forms, ensuring our UI always matched the valid options from our code. This makes it easy to update order statuses in the future — just update the enum, and both UI and validation stay in sync.
Next, we added a 'label' to our enum cases so we can display more user-friendly names in the UI, rather than just the enum value itself. To further integrate enums, we updated the Order model so that when we access the order status, we actually get an enum instance instead of just a string. That way, we can take advantage of things like getting the label directly from the model.
Overall, this recap should reinforce how enums help keep your code clean, consistent, and easier to maintain, especially when you have columns in your database with a set of limited, discrete values.