Back to Course |
Laravel User Timezones Project: Convert, Display, Send Notifications

Bonus Package: Snooze

We have to mention that there is a package that does our workflow (or at least similar) for us. It is called Snooze.

It is a very simple package that allows you to do the following:

// 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'));

By simply adding a trait to your User Model:

app/Models/User.php

 
use Thomasjohnkane\Snooze\Traits\SnoozeNotifiable;
use Illuminate\Notifications\Notifiable;
 
class User extends Model {
use Notifiable, SnoozeNotifiable;
 
// ...
}

Once a message is scheduled - it will be picked up by an automatically registered command that runs every minute. Or you can run the command manually:

php artisan snooze:send

This package was also mentioned on Laravel News.