This episode is for members only

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

Get started
Already a member? Sign in to continue
Playing
06. Creating the appointments table

Episodes

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

Transcript

00:00
Lastly, let's work on our appointments schema and the relationships that we need.
00:05
So again, let's go ahead and create out a model for this. And that's, of course, going to be appointment. Let's open up the schema and get this working. So let's open up appointments table here and fill this in.
00:18
So the first thing that we want is something other than an ID. So we're going to choose a UUID and we're going to generate that automatically in this episode. And then we're going to have a foreign ID that relates to the service that the appointment is actually booked for.
00:34
So that's really important. We're going to do probably the same thing for our employee as well. And then similar to pretty much everything else, we're going to have a starts at and an ends at.
00:45
But this is going to be a date time because they're going to be combined. So let's say this starts at a certain time and ends at a certain time. Now, of course, what we could do with the starts at date is work out the ends at date by the service that's been booked.
00:58
But we're going to store it in this. So when we're going through and checking availability for a particular employee, we can use the starts at and ends at date to cut this out. It's going to be much easier to store these separately in the database.
01:12
OK, so last of all, let's create out just a time stamp in here whether this is cancelled or not. So I'm going to call this cancelled at. And that's also going to be nullable because obviously it's not always going to be cancelled. And then really, the rest of this is up to you.
01:27
So I'm going to choose just to store the name of the customer and the email address of the customer. But of course, you can customize this to whatever data you want to store in here. OK, let's go ahead and run our migrations again.
01:42
And we are done with our appointments table. Let's go straight over to the appointment model. And the first thing that I'm going to do is set guarded to an empty array. So we can just fill in whatever we need inside of here.
01:55
We also want to think about our casts as well. So we are going to cast the starts at date to a date time. Remember, this is a date object that has the time in as well now. And we'll do the same thing for ends at as well and cast that.
02:10
OK, so for the relationships here, again, we're going to have a service. So this belongs to a service. So let's just create that simple relationship out here. Belongs to a service.
02:20
And we'll also have an employee as well that this belongs to. So this belongs to an employee. And that is pretty much it for our relationships. And the last thing we want to do is automatically generate a UUID when this is created.
02:41
So let's go and create out a public static function called booted. So this will be called after this is booted. And then we're going to say while this is being created. So as it's creating, we are going to take the appointment.
02:56
And let's just type in that in there. And we're going to assign the UUID using Laravel String Helper. And we're going to use the UUID method. So that will generate a UUID as it's being created.
03:09
So when it is stored in the database, we will then have a UUID filled in there. We'll test this out much later when it comes to actually creating an appointment after we've gone through checkout. But for now, that is our appointments table done.
36 episodes3 hrs 4 mins

Overview

Building an availability calendar and booking system is a notoriously difficult problem to solve. That’s exactly what we’re going to cover in this course.

Step by step, we’ll build an appointment slot generator that calculates availability based on employee schedules, employee’s booked time off, the length of service chosen, existing appointments, and cancelled appointments.

For maximum flexibility, we’ll also allow multi-employee availability checks, so we’ll be able to see every employee who can perform a service (and their available slots).

To finish up, we’ll create an entire booking flow with Livewire, including a beautiful booking calendar that shows detailed availability across multiple dates, the ability to choose a time slot — and finally the ability to book an appointment.

Phew. We’ve got a lot to learn — let’s build a booking system with Livewire!

Alex Garrett-Smith
Alex Garrett-Smith
Hey, I'm the founder of Codecourse!

Comments

No comments, yet. Be the first to leave a comment.