In this episode, we focus on fetching and organizing your service's availability data so we can feed it into our booking calendar!
We start by working inside the checkout controller to grab all the availability information that we need—from available employees to the days and time slots you can book. We walk through setting up the code to fetch availability based on employee and service, for a set date range (like the next month), with a few tricks to make it dynamic later (e.g., changing when the user flips through the calendar).
Next, we dive into structuring this data nicely for the front end by creating custom API resources—first an AvailabilityResource
for the days, and then a nested SlotResource
for specific time slots within each day. We make sure these resources only return the necessary info, keeping things clean and ready for our calendar UI.
We also refactor how slots track available employees to use collections (which is just a bit neater in Laravel!), and check everything still works by running the tests. Finally, we ensure we include the right info—like the number of slots per date, which employees are free for a slot, and formatting the times correctly so they're easy to display in the calendar and easy to use when making a booking.
Now with all your structured availability ready to go, we're set up to make the calendar show available and unavailable days, display the correct slots, and handle bookings on the right date/time. Next episode, we'll start hiding those unavailable dates in the calendar!