In this episode, we focus on cleaning up our booking slots by removing any slots that don't have any available employees – basically, empty slots. After assigning employees to their available slots, we want to tidy things up before moving on to filter out slots that have already been booked.
We start by creating a removeEmptySlots
method that takes our current collection of slots and filters out any slot where there aren't any employees assigned. We use Laravel's collection filter
method to accomplish this, and we also put a handy helper function called hasEmployees
into our Slot class. This makes it really straightforward to check if a slot should stay or go.
A nice side effect of our filtering is that if an entire date ends up with zero available slots, the whole day gets filtered out too. So, if no one is available for a specific day, it simply won't appear in our list – much cleaner!
For display purposes, we decide to keep dates visible on the calendar even if they don't have any slots, just graying them out to indicate they're unavailable. After filtering, we test out some exclusions by removing all employee availability for a day and confirm that the interface reflects this correctly. Once that's verified, we roll back our changes and get ready for the next step: filtering out slots that already have booked appointments.
So, by the end of this episode, we've got a much tighter and more logical set of available slots for users to book from!