In this episode, we get hands-on and start by creating our initial product record right at the beginning of our multi-step form. We walk through updating our database: first, generating the Product
model and its migration, and deciding which fields we need (title, description, image path, and a published boolean). We talk about making fields like the image path nullable since those details come later in our flow, and set up the relationship so that products belong to a user.
You'll see how to tweak the migration to add a user_id
foreign key, run the migrations, and set up the basic Eloquent relationship in our models. Then, we jump over to the frontend, set up a submit method to handle the initial form submission, validate the data, and instantly create a product attached to the currently logged-in user.
We keep things simple by only storing what's currently available and use features like Livewire's only
method to ensure we're only saving the form fields we've filled out so far. Finally, we check it's all running smoothly by seeing the product appear in our database, and set ourselves up for the next episode, where we'll focus on how to carry the product's state smoothly through later steps like uploading an image and publishing.