Laravel Zap logo
Getting Started

Quick Start

Create your first schedules.

Quick Start

Here is a full example of a typical workflow.

use Zap\Facades\Zap;

// 1️⃣ Define working hours
Zap::for($doctor)
    ->named('Office Hours')
    ->availability()
    ->forYear(2025)
    ->addPeriod('09:00', '12:00')
    ->addPeriod('14:00', '17:00')
    ->weekly(['monday', 'tuesday', 'wednesday', 'thursday', 'friday'])
    ->save();

// 2️⃣ Block lunch break
Zap::for($doctor)
    ->named('Lunch Break')
    ->blocked()
    ->forYear(2025)
    ->addPeriod('12:00', '13:00')
    ->weekly(['monday', 'tuesday', 'wednesday', 'thursday', 'friday'])
    ->save();

// 3️⃣ Create an appointment
Zap::for($doctor)
    ->named('Patient A - Consultation')
    ->appointment()
    ->from('2025-01-15')
    ->addPeriod('10:00', '11:00')
    ->withMetadata(['patient_id' => 1, 'type' => 'consultation'])
    ->save();

// 4️⃣ Get bookable slots (60 min slots, 15 min buffer)
$slots = $doctor->getBookableSlots('2025-01-15', 60, 15);
// Returns: [['start_time' => '09:00', 'end_time' => '10:00', 'is_available' => true, ...], ...]

// 5️⃣ Find next available slot
$nextSlot = $doctor->getNextBookableSlot('2025-01-15', 60, 15);

// 6️⃣ Check if a specific time range is bookable
$isAvailable = $doctor->isBookableAtTime('2025-01-15', '15:00', '16:00');
// Returns: true or false

Using the Helper Function

Instead of using the Zap facade, you can use the global zap() helper function. Both approaches are equivalent—the helper just doesn't require importing the facade class.

Facade vs Helper

// Facade (requires import)
use Zap\Facades\Zap;
Zap::for($doctor)->availability()...

// Helper (no import needed)
zap()->for($doctor)->availability()...

Complete Examples with zap()

Here are the same examples using the helper function:

Creating Availability Schedules

// Define working hours
zap()->for($doctor)
    ->named('Office Hours')
    ->availability()
    ->forYear(2025)
    ->addPeriod('09:00', '12:00')
    ->addPeriod('14:00', '17:00')
    ->weekly(['monday', 'tuesday', 'wednesday', 'thursday', 'friday'])
    ->save();

// Block lunch break
zap()->for($doctor)
    ->named('Lunch Break')
    ->blocked()
    ->forYear(2025)
    ->addPeriod('12:00', '13:00')
    ->weekly(['monday', 'tuesday', 'wednesday', 'thursday', 'friday'])
    ->save();

Creating Appointments

// Create an appointment
zap()->for($doctor)
    ->named('Patient A - Consultation')
    ->appointment()
    ->from('2025-01-15')
    ->addPeriod('10:00', '11:00')
    ->withMetadata(['patient_id' => 1, 'type' => 'consultation'])
    ->save();

Checking for Conflicts

// Create a schedule and check for conflicts
$schedule = zap()->for($doctor)
    ->named('Patient B - Follow-up')
    ->appointment()
    ->from('2025-01-15')
    ->addPeriod('10:00', '11:00')
    ->save();

// Check if the schedule has conflicts
$hasConflicts = zap()->hasConflicts($schedule);
$conflicts = zap()->findConflicts($schedule);

if (!$hasConflicts) {
    // Schedule created successfully, no conflicts
} else {
    // Handle conflicts - $conflicts contains overlapping schedules
}

Note: Both the facade and helper function are equivalent. Choose whichever approach fits your coding style or project conventions.