Let's send the following emails to our new Users:
- Sign-Up Confirmation - will be sent 1 hour after they register
- Welcome to the community - will be sent 3 days after they register
- Upsell to Subscription - will be sent 1 week after they register
Add the SnoozeNotifiable
trait to your user model
use Thomasjohnkane\Snooze\Traits\SnoozeNotifiable;
class User {
use SnoozeNotifiable;
}
-
Create the "sign-up confirmation" notification:
php artisan make:notification SignUpConfirmation --m
-
Create the "welcome to the community" notification:
php artisan make:notification WelcomeToCommunity --m
-
Create the "upsell subscription" notification:
php artisan make:notification UpsellSubscription --m
-
Create a User Observer to watch for the sign-ups
php artisan make:observer UserObserver --model=User
- Added
app/Observers/UserObserver.php
- You must register this observer. Look here for help registering your UserObserver class
- Added
-
Schedule the Notifications once a User is
created
// use Carbon\Carbon; public function created(User $user) { $now = Carbon::now(); $user->notifyAt(new SignUpConfirmation($user), $now->addHour()); $user->notifyAt(new WelcomeToCommunity($user), $now->addDays(3)); $user->notifyAt(new UpsellSubscription($user), $now->addWeek()); }
- Our notification will be saved in our
scheduled_notifications
table. - The
snooze:send
command is scheduled by the package to run every minute by default. It will send the notifications for us when they are ready. - All you need to do is make sure your "schedule:run" command is running as well.
- Read here for more information on how to run your scheduler.