laraveljutsu/zap
Zap adds flexible calendar scheduling to Laravel: manage resource availabilities, appointments, blocked times, and custom schedules (doctors, rooms, staff). Includes patterns plus querying/availability checks for booking, shifts, and shared spaces.
Installation:
composer require laraveljutsu/zap
php artisan vendor:publish --provider="Zap\ZapServiceProvider"
php artisan migrate
Make a model schedulable:
use Zap\Models\Concerns\HasSchedules;
class Doctor extends Model
{
use HasSchedules;
}
First use case: Define working hours for a doctor
use Zap\Facades\Zap;
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();
Check availability:
$slots = $doctor->getBookableSlots('2025-01-15', 60, 15);
Define Schedules:
Zap::for($model)->named('Schedule Name')->[type]() where [type] is availability(), appointment(), blocked(), or custom().weekly(), monthly(), everyThreeWeeks(), etc.addPeriod('start', 'end').Recurring Patterns:
daily(), weekly(['monday', 'friday']).monthly(['days_of_month' => [1, 15]]) or ordinal methods like firstWednesdayOfMonth().everyThreeWeeks(), everyFourMonths().Querying:
$model->getBookableSlots('2025-01-15', 60, 15).$model->getNextBookableSlot('2025-01-15', 60, 15).Zap::findConflicts($schedule).Metadata:
withMetadata(['key' => 'value']) for custom data storage.Validation Rules:
noOverlap(), allowOverlap(), maxDuration(120), workingHoursOnly('09:00', '17:00') for custom validation.Frontend Integration:
getBookableSlots() to fetch available time slots for a date range and display them in a calendar UI.isBookableAtTime() to validate user selections in real-time.Event Triggers:
Zap\Events\ScheduleCreated, Zap\Events\ScheduleUpdated, and Zap\Events\ScheduleDeleted to trigger notifications or sync external systems.Testing:
Zap::fake() to mock schedules in unit tests.assertTrue($model->isBookableAtTime(...)).Appointment Booking:
Resource Management:
Employee Shifts:
Timezone Handling:
UUID/ULID Support:
Overlapping Schedules:
noOverlap() is enabled. If you need overlapping schedules, explicitly use allowOverlap().Date Range Conflicts:
from() and to(), ensure the range is inclusive and correctly handles timezone transitions.Recurrence Edge Cases:
Querying Schedules:
dd($model->schedulesForDate('2025-01-15')->get()) to inspect all schedules for a date.Conflict Detection:
Zap::findConflicts($schedule) to debug overlapping schedules. Enable conflict_detection in config/zap.php for detailed conflict reports.Time Periods:
dd($schedule->periods) to ensure they match expectations.Buffer Minutes:
time_slots.buffer_minutes in config/zap.php to control the gap between appointments.Default Rules:
default_rules to change the default behavior for new schedules (e.g., no_overlap).Validation:
config/zap.php under validation to enforce business logic.Custom Schedule Types:
Zap\Models\Schedule to add custom fields or logic.Recurrence Patterns:
Zap\Recurrence\Recurrence and registering them in the service provider.Event Listeners:
AI Agent Support:
zap-schedules, zap-availability, zap-recurrence) for AI-assisted development and documentation.Indexing:
schedulable_id, type, and date columns are indexed for faster queries.Caching:
Batch Processing:
How can I help you explore Laravel packages today?