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

Saturnlai's avatar

Checking for overlapping appointments and limit attendees

I am trying an appointment' each slot is 15 or 30 minutes and that's each slot will limit number of attendees. But on the frontend I'd want display number of attends of all slots.

Example:

  • Capacity: 20 people

  • Min Slot Minutes: 15 minutes

  • Slot 1: 8:00-8:15 - number of attendees is 15 people (By User 1)

  • Slot 2: 8:00-8:15 - number of attendees is 3 people (By User 2)

  • Slot 3: 8:00 - 8:30 - number of attendees this time max 2 people. (By User 3)

The total number of attendees is what I want to show Appointment 1 hour from 8:00- 9:00.

0 likes
5 replies
Saturnlai's avatar

@webrobert This is my code below

	$start_date         = data_get($params, 'start_date');
    $end_date           = data_get($params, 'end_date');
    $min_slot_minutes   = CarbonInterval::minutes(data_get($channel, 'appointment_min_duration', 15));

    $attendees = $this->attendees->queryAttendees([
        'channel_id'    => (int) data_get($params, 'channel_id'),
        'client_id'     => (int) data_get($params, 'client_id'),
        'venue_id'      => $venue->id,
        'start'         => Carbon::make("{$start_date} {$venue->opening_hour}"),
        'end'           => Carbon::make("{$end_date} {$venue->closing_hour}")
    ]);

    $periods    = new CarbonPeriod($start_date, '1 day', $end_date);
    $schedules  = [];
    foreach($periods as $period ) {
        $from   = Carbon::make("{$period->format('Y-m-d')} {$venue->opening_hour}");
        $to     = Carbon::make("{$period->format('Y-m-d')} {$venue->closing_hour}");
        foreach(new CarbonPeriod($from, $min_slot_minutes, $to->sub($min_slot_minutes)) as $slot) {
            $end = $slot->copy()->add($min_slot_minutes);
            
            $schedules[] = [
                'start'     => $slot->format('Y-m-d H:i:s'),
                'end'       => $end->format('Y-m-d H:i:s'),
                'attendees' => 0 // I want push attendees here
            ];
        }
    }

    return $schedules;
webrobert's avatar

@Saturnlai, there was another thread here on time slots that could be helpful... I can't seem to find it at the moment. But why not query the events instead of the attendees and do a withCount for the attendees?

Saturnlai's avatar

@webrobert An appointment there are many objects attendees such as: Guest number, sellers..... So i can't use withCount in that case.

Please or to participate in this conversation.