In this episode, we're working on building out a simple order creation form. We start with a blank page and a controller that's set up, but not doing much yet. The goal is to let users select an order status (like "placed," "shipped," or "canceled") from a <select>
dropdown, and we'll use an enum for these statuses to keep our available options centralized and easy to maintain.
We walk through how to pass all the enum cases down to the view, using the cases
method, and then iterate over those statuses in the form, making sure our dropdown always reflects the underlying enum. That means any new status you add to your enum will immediately show up in the form too. After that, we wire up the form submission so that new orders can be created with their selected status, making sure the controller, route, and model all work together.
We also spot and fix a couple of common mistakes, like forgetting the name
attribute on the select field and adding the fillable property to the model. Once all that's sorted, we test it out, and everything works! But, as we see, right now you could still submit invalid statuses—so enforcing enum values at the storage/validation level is something we'll look at next. Before that, though, the next step is making the form display more user-friendly values with enum helper methods.