Automate Future Notifications and Reminders with Laravel Snooze

Automate Future Notifications and Reminders with Laravel Snooze

Laravel Snooze is a package by Thomas Kane, which simplifies automating future notifications and reminders in Laravel.

The package’s readme has some typical use-cases for this package:

  • Reminder system (1 week before appt, 1 day before, 1 hour before, etc)
  • Follow-up surveys (2 days after purchase)
  • On-boarding Email Drips (Welcome email after sign-up, additional tips after 3 days, upsell offer after 7 days)
  • Short-Term Recurring reports (send every week for the next 4 weeks)

Snooze provides a trait for your models called SnoozeNotifiable that adds a notifyAt() method:

use Thomasjohnkane\Snooze\Traits\SnoozeNotifiable;

class User extends Model {
    use SnoozeNotifiable;

    // …
}

// Schedule a birthday notification
$user->notifyAt(new BirthdayNotification, Carbon::parse($user->birthday));

// Schedule for a week from now
$user->notifyAt(new NextWeekNotification, Carbon::now()->addDays(7));

// Schedule for new years eve
$user->notifyAt(new NewYearNotification, Carbon::parse('last day of this year'));

You can even send anonymous notifications using the ScheduledNotification::create() method:

$target = (new AnonymousNotifiable)
    ->route('mail', 'hello@example.com')
    ->route('sms', '56546456566');

ScheduledNotification::create(
     $target, // Target
     new ScheduledNotificationExample($order), // Notification
     Carbon::now()->addDay() // Send At
);

If you have some logic that should stop the notification from sending, you can define logic in the notification class:

public function shouldinterrupt($notifiable) {
    return $this->invoice->is_paid;
}

For more detailed info, check out Thomas Kane’s detailed article Scheduling Laravel notifications using Snooze.

The options and code API for this package provide a delightful experience for sending notifications in the future, so be sure to read through all the documentation.

You can learn more about this package, get full installation instructions, and view the source code on GitHub at thomasjohnkane/snooze.

Filed in: News
Laravel News Partners

Laravel Jobs

Backend Software Engineer (PHP Developer)
Austin TX, Bonita Springs FL
Certified eSupport Corp
Laravel Developer
Glendale, CA (COVID Remote)
Jogg, Inc
Senior PHP Engineer
Remote, USA Only
Kittyhawk
Full Stack Engineer
Remote
Shelterluv
Kickass LaraDev!
Remote
Megaverse

Newsletter

Join 31,000+ others and never miss out on new tips, tutorials, and more.