In this episode, we're wrapping up our setup work by focusing on appointments. We'll dive into how appointments are represented in our system — essentially as records with a start and end time, an indicator if it's been canceled, and whatever customer data we want to collect at booking time.
We walk through creating an appointments
table, using a UUID as the primary identifier instead of a simple numeric ID (great for better security and referencing from the client side). The table includes foreign keys for both the booked service and the employee, as well as fields for start/end times, a cancelation timestamp, and simple customer info (in this example, just name and email, but you could expand it as needed).
On the Laravel side, we set up migrations, the model, and a factory for appointments, which will help us with testing later on. The model is configured to handle date casting for start and end times, a handy booted method ensures UUIDs are auto-generated, and we add relationships to services and employees for easy lookups.
Finally, we add the missing link back on the employee side: an appointments
relationship so we can efficiently check all appointments for a specific employee when calculating their availability.
With the appointments structure in place, we're now ready to move on to building the core business logic—in the next episode, we'll take a closer look at working with date periods and see how they'll help us calculate available booking slots.