PHP code example of ismail-rt / laravel-atlas-drip
1. Go to this page and download the library: Download ismail-rt/laravel-atlas-drip library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
ismail-rt / laravel-atlas-drip example snippets
// THE NAIVE PATTERN (DANGEROUS IN PRODUCTION)
User::where('email_verified_at', '<=', now()->subDays(3))->get()->each(function ($user) {
Mail::to($user)->send(new OnboardingMail());
});
return [
/*
|--------------------------------------------------------------------------
| Engine Enabled
|--------------------------------------------------------------------------
*/
'enabled' => env('LAD_ENABLED', true),
/*
|--------------------------------------------------------------------------
| Global Inter-Campaign Cooldown (Hours)
|--------------------------------------------------------------------------
| If a recipient received ANY lifecycle email in the last X hours,
| subsequent campaign emails are paused to prevent inbox bombing.
*/
'global_cooldown_hours' => (int) env('LAD_COOLDOWN_HOURS', 48),
/*
|--------------------------------------------------------------------------
| Historical Enrollment Cutoff
|--------------------------------------------------------------------------
| Optional timestamp (e.g. '2026-09-01 00:00:00'). Recipients whose anchor
| is prior to this date are rejected from enrollment unless a prior notification
| log proves they were already in the campaign.
*/
'enrollment_started_at' => env('LAD_ENROLLMENT_STARTED_AT', null),
/*
|--------------------------------------------------------------------------
| Default Recipient Model
|--------------------------------------------------------------------------
*/
'recipient_model' => env('LAD_RECIPIENT_MODEL', App\Models\User::class),
/*
|--------------------------------------------------------------------------
| Database Table Names
|--------------------------------------------------------------------------
*/
'table_names' => [
'states' => env('LAD_TABLE_STATES', 'lad_campaign_states'),
'logs' => env('LAD_TABLE_LOGS', 'lad_notification_logs'),
],
/*
|--------------------------------------------------------------------------
| Signed Unsubscribe Routing
|--------------------------------------------------------------------------
*/
'routes' => [
'enabled' => true,
'prefix' => 'lad',
'middleware' => ['web'],
],
];
use Lad\Facades\Drip;
// Aliases available:
// use Lad\Facades\Lifecycle;
// use Lad\Facades\Lad;
use Lad\Campaign;
use Lad\Step;
// 1. Onboarding Campaign
Drip::register(
Campaign::make('onboarding')
->priority(10) // Lower number = evaluated first
// Who qualifies for this campaign?
->eligible(fn ($user) => $user->hasVerifiedEmail() && !$user->isAdmin())
// What is the reference time clock?
->anchor(fn ($user) => $user->email_verified_at)
// Maximum age for initial enrollment (failsafe against first-deploy explosions)
->maxEnrollmentAgeDays(10)
// Goal completion: cancel when user achieves desired action
->cancelWhen(fn ($user) => $user->properties()->exists())
// Sequential steps
->steps([
Step::make('day3')
->offsetDays(3)
->notification(OnboardingReminderNotification::class),
Step::make('day5')
->offsetDays(5)
->minimumGapDays(2)
->notification(OnboardingTipsNotification::class),
Step::make('day7')
->offsetDays(7)
->minimumGapDays(2)
->notification(function ($user) {
return new OnboardingDiscountNotification(promoCode: 'WELCOME15');
}),
])
);
// 2. Recurring Streak Campaign (e.g., Idle Win-Back)
Drip::register(
Campaign::make('idle_winback')
->priority(20)
->eligible(fn ($user) => $user->properties()->exists())
->anchor(fn ($user) => $user->last_login_at)
// Custom instance key isolates recurring streaks
->instanceKey(fn ($user) => $user->last_login_at?->utc()->format('Y-m-d-H-i-s'))
->cancelWhen(fn ($user) => $user->last_login_at?->gt(now()->subDays(7)))
->steps([
Step::make('idle_reminder')
->offsetDays(7)
->notification(WeMissYouNotification::class),
])
);
use Illuminate\Support\Facades\Schedule;
Schedule::command('drip:send')->hourly();
use Illuminate\Support\Facades\Event;
use Lad\Events\StepDispatched;
Event::listen(StepDispatched::class, function (StepDispatched $event) {
Log::info("Dispatched {$event->campaign->getName()}:{$event->step->getKey()} to #{$event->recipient->id}");
});