This episode is for members only

Sign up to access "Build an Appointment Booking System With Inertia" right now.

Get started
Already a member? Sign in to continue
Playing
16. Removing empty slots

Episodes

0%
Your progress
  • Total: 5h 0m
  • Played: 0m
  • Remaining: 5h 0m
Join or sign in to track your progress

Transcript

00:00
OK, so we've added employees into slots based on each of these employees availability.
00:04
That is all done. Let's go ahead and just remove any empty slots just to clear things up before we start to remove any slots based on when appointments have already
00:15
been booked. OK, so down here, we're going to go ahead and just call another method just to, again, filter through everything.
00:22
And let's call this remove empty slots. And what we want to do is reassign the range. So this is going to take in, of course, the range itself. And then it's just going to return that range
00:34
and then reassign it back to that before we return it inside of here. And we don't want to do this within the loop because we only need to delete any empty slots once
00:44
after all of the employees have been added. OK, let's go ahead and create this method out just down here. So remove empty slots. And we know that that is going to take in a Laravel
00:53
collection. And that is going to be our range. OK, let's add in our function definition there. And we're done.
01:00
OK, so what we're going to do here is immediately return this range. But we're going to filter this out. So this shouldn't look any different.
01:07
We should see everything that we saw before. But now what we can do is go ahead and use filter. Because we're working with a collection, we can use this filter method, which
01:16
takes in a condition within here. So we can return false, for example. That's going to get rid of everything. Now, the good thing about this filter
01:26
is we're going to look inside of each of the slots. But this will also, if all of the slots within a date are removed, the date will be removed as well, which is really good.
01:34
We don't want to see any dates available if there are no slots for that particular day. So if Alex and Mabel both didn't work on Saturday and Sunday, that date would just be unavailable.
01:45
It wouldn't be in there, which is exactly what we need. OK, so now that we've done this, let's actually make this work. So each of the things that we get in here is a date. So let's go ahead and bring that in.
01:55
And inside of here, we're going to reassign the slots to a filtered version of the slots. Now, what that means is we're filtering the slots. But then out of here, we're also filtering the dates,
02:06
which is what I just mentioned. So let's go ahead and filter on the slots here. We'll go ahead and bring in each of them slots. And what is the condition?
02:15
Well, the condition for a slot being available is if there are employees within that slot. So what we could do is open up our slot class and just create our helper method in here called hasEmployees.
02:29
And we could return if this employees is empty. So if it's not empty, it does have employees. So in here, we're going to return slot hasEmployees. And we're done.
02:43
That will have filtered out all of them slots. So now in here, we're just going to return true. And we should be good. Now, yeah, so I think, actually, the best way to do this
02:53
is to keep the date in there, because we want that to be added to the calendar. But then we could just show a grayed out version of the calendar if that's not available.
03:03
So if I give that a refresh, both dates are available here. Now, that should have filtered that down massively. So today, for example, again, right now, it's just about coming up to 3 o'clock.
03:14
So we should have this slot available, which is 3 o'clock, of course. And the employees within here that can do that are Alex and Mabel, and then so on and so forth. So them slots are both available.
03:28
If we look at this date here, we've got 16 slots, because, of course, that's tomorrow. We don't have any bookings yet. We've not filtered bookings out.
03:36
So all of these slots are available from 9 o'clock. And of course, both employees can do this as well. Now, what we could do is just to test this out, add in a schedule exclusion for both of these employees.
03:49
So I'm going to go ahead and say that, let's say, tomorrow. So let's say the 31st from 9 in the morning till 5 for both employees. And we come over. We've got this date here.
04:10
And sure enough, we have no slots available. So we will keep the date in there. At least then we can add it to the calendar, but we can gray it out if there aren't any slots available.
04:19
I think that makes more sense. OK. So we've now got a much more filtered down version of all of our dates that we've requested and all of the slots in there that we can do.
04:29
So I'm just going to go ahead and get rid of these exclusions here. We can always add them back later. And next, let's look at filtering out dates or slots where appointments have already been booked.

Episode summary

In this episode, we focus on cleaning up our available slots after assigning employees based on their availability. Now that employees are slotted in, it’s time to tidy things up by removing any empty slots—basically, getting rid of times where no employees are available.

We walk through creating a new method called removeEmptySlots, which filters out any slots without employees. We take a look at how filtering on the collection not only removes empty slots, but also completely removes dates that have no available slots, which keeps our schedule view neat and relevant. For the rare times when a date has no slots but should remain on the calendar (so users know the day exists), we talk about graying out that day as unavailable.

We put this into practice by adding and removing some schedule exclusions and checking how the filtering works in real-time. The end result: our user will only ever see dates and times that actually have someone available—no wasted clicks or confusion.

Coming up next, we’ll tackle how to filter out slots that already have appointments booked, taking our availability system to the next level!

Episode discussion

No comments, yet. Be the first!