Use the composer CLI command to install Zap for Laravel in a Laravel application:
composer require laraveljutsu/zap
Publish and run the migrations to set up the required database tables:
# Publish and run migrations
php artisan vendor:publish --tag=zap-migrations
php artisan migrate
schedules and schedule_periods tables, as well as Schedule and SchedulePeriod models, do not already exist in your project to avoid conflicts.If you need to customize the package configuration, publish the config file:
# Publish configuration file
php artisan vendor:publish --tag=zap-config
Add the HasSchedules trait to any model that should support scheduling:
use Illuminate\Foundation\Auth\User as Authenticatable;
use Zap\Models\Concerns\HasSchedules;
class User extends Authenticatable
{
use HasSchedules;
}
Once installed, you can immediately start creating schedules using Zap for Laravel's fluent API:
use Zap\Facades\Zap;
// Create a simple appointment
$schedule = Zap::for($user)
->named('Doctor Appointment')
->description('Annual checkup')
->on('2025-03-15') // on() is an alias of from()
->addPeriod('09:00', '10:00')
->save();
// Weekly team meeting
$meeting = Zap::for($user)
->named('Team Standup')
->from('2025-01-01')
->to('2025-12-31')
->addPeriod('09:00', '09:30')
->weekly(['monday', 'wednesday', 'friday'])
->save();
// Check if user is available
$available = $user->isAvailableAt('2025-03-15', '14:00', '16:00');
if ($available) {
// User is free, proceed with booking
echo "User is available!";
}
Once the installation is complete, you can start using Zap for Laravel's scheduling features in your application. The package provides a comprehensive set of tools for managing schedules and recurring events.