In this episode, we take our existing slot range generator—which gives us a plain Laravel collection of custom date objects—and take things up a notch. Instead of just working with the standard collection, we create our own custom DateCollection
class that extends Laravel's base collection. This lets us add all sorts of handy methods tailored to our booking logic.
The main enhancement we build here is a helper to find the first available date for bookings. We don't want the UI to default to today if no slots are left, so our custom collection now helps us pick the first date with available slots. We run through how to implement this method, put it to the test in our web routes, and verify that it picks the correct date depending on the available slots (for example, skipping today if we've passed working hours).
This little change gives us flexibility and keeps our code neat, as we now have a better place for booking-related helpers. Next up, we'll be writing tests to make sure our new custom collection behaves as expected, and then start hooking this logic up to our UI!