In this episode, we're diving into how to actually store an appointment in the database—and there’s a bit more to it than just a simple insert!
First, we walk through what needs to go into our appointments
table, specifically the service and employee IDs, as well as the start and end times for the appointment. The UUID gets generated for us, but we have to calculate the end time by adding the duration of the service to the start time. We show how to set up the route and controller (AppointmentStoreController
), wire everything up with the client using Inertia, and make a test booking just to see if the data is flowing correctly.
After the basic setup, we break down how to properly collect and validate the incoming data. This includes making sure the employee and service really exist, getting the name and email in, and handling the all-important date and time fields. Using Laravel’s Carbon, we calculate both start and end times based on the chosen slot and service duration.
We then walk through adding validation by creating a custom Form Request (AppointmentStoreRequest
) to keep things clean and tidy. This ensures only valid appointments get through. Finally, we give everything a spin, check the database, and confirm that the right slots, durations, and details are being saved.
At the very end, we tee up the next episode, where we’ll tackle appointment collisions—so two users can’t book the same slot at the same time. Stay tuned for that!