In this episode, we focus on setting up the appointments table in our application. We start by defining the appointments schema, making sure to include a UUID (which we set up to generate automatically for each appointment). We also add foreign keys to link each appointment to a specific service and employee, ensuring proper relationships within our data structure.
Next up, we add useful datetime fields: starts_at
and ends_at
, allowing us to keep track of the exact time slots for each appointment. We talk about why it's better to store both fields (rather than just one and calculating the other), especially for checking employee availability. There’s also a cancelled_at
nullable field for tracking when (if ever) an appointment is cancelled.
For customer data, we keep it simple for now—a name and email—but we mention that you can customize this as needed. After the schema, we run database migrations to get the table up and working.
Then, we turn to the Laravel model for Appointment. We set up guarded fields, ensure our date fields are cast properly, and define the model relationships to both Service and Employee. To wrap up, we automate UUID generation whenever a new Appointment is created using Laravel’s String helper inside a booted function.
By the end of this episode, our appointments table is all set up and ready to be used. We’ll come back to test and use this when we handle creating appointments after checkout.