Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

idcreatv's avatar

Creating a non-clashing appointments booking query…

I’m hoping someone can advise the best way of handling clashing appointments in a salon system I’m looking to build.

In its most basic form, the admin will add staff members and treatments to the system (see below tables - I’m ignoring other columns right now, just the ones I think I need).

When the customer goes to the site, they’ll choose the treatment and date. I’m thinking that the system then looks for any treatments on this date and blocks the customer from booking a treatment with the staff members involved for that time slot (i.e. 11:00 - 11:45 is greyed out).

Treatments are recorded in blocks of 15 minutes (so 15, 30, 45, 60 mins etc), there’s no 20 or 35 minute treatments.

So, the basic columns for the tables could be something like this:

Staff > id | name

Treatments > id | title | duration (in minutes)

Appointments > id | treatment_id | staff_id | start_date_time | end_date_time

So, Barbara chooses a nails treatment (15 minutes) and a date (25/05/21).

The system returns all available times for that day (i.e. as a scrolling list/dropdown) which Barbara can choose from.

At 10:30 on 25/05/21 Claire is doing a 30 minute treatment with a customer, so the 10:30 appointment slot for her is disabled so you can’t select her, however you can select Jane and Dawn who are both available at that time etc.

The problem is that I can’t quite get my head around how to check for appointments.

I was thinking of taking the start time and adding the duration (in minutes) via Carbon to get an end time. I’d then check all appointments to see which staff members are unavailable for the period the customer has selected.

Can anyone advise how I would query the appointments to do this, or if there’s a different way altogether that I’m maybe missing?

Any advice most appreciated!

0 likes
2 replies
jlrdw's avatar

Have you thought about a calendar app to assist in this, like https://github.com/acaronlex/laravel-calendar

I have done similar, but I just break up each day into time slots, so a query if a time slot on a certain day tells me if the slot is available.

However it's been a long while and it was done in dbase.

idcreatv's avatar

Thanks for the link - I'll take a look and see if it does what I need.

I suppose I was just trying to get the logic right in my head as there's bound to be other jobs in the future where I have the same issue so if I solve it straight off the bat it'll make things easier as and when they crop up.

Please or to participate in this conversation.