### Install Laravel Snooze via Composer - Bash Source: https://github.com/thomasjohnkane/snooze/blob/master/README.md This command installs the laravel-snooze package using Composer, the PHP dependency manager. It downloads the package and its dependencies into your Laravel project. ```bash composer require thomasjohnkane/snooze ``` -------------------------------- ### Run Snooze Migrations - Bash Source: https://github.com/thomasjohnkane/snooze/blob/master/README.md After installing the package, this command runs the database migrations provided by laravel-snooze. This sets up the necessary table to store scheduled notifications. ```bash php artisan migrate ``` -------------------------------- ### Registering Snooze Service Provider (PHP) Source: https://github.com/thomasjohnkane/snooze/blob/master/docs/register-provider-and-facade.md Adds the snooze package's service provider class to the `providers` array in Laravel's `config/app.php` file. This registers the package's core services with the Laravel application container. This step is optional for Laravel 5.5+ with auto-discovery enabled. ```PHP Thomasjohnkane\ScheduledNotifications\ServiceProvider::class, ``` -------------------------------- ### Registering Snooze Facade (PHP) Source: https://github.com/thomasjohnkane/snooze/blob/master/docs/register-provider-and-facade.md Registers the snooze package's facade class in the `aliases` array within Laravel's `config/app.php` file. This allows for easier access to the package's functionality via a static interface. This step is optional for Laravel 5.5+ with auto-discovery enabled. ```PHP Thomasjohnkane\ScheduledNotifications\Facades\ScheduledNotification::class, ``` -------------------------------- ### Schedule Delayed Notification using notifyAt - PHP/Laravel Source: https://github.com/thomasjohnkane/snooze/blob/master/docs/examples/basic-delayed-notification.md This snippet demonstrates how to schedule an existing notification (`OneWeekAfterNotice`) to be sent to a notifiable model (the authenticated user) at a future datetime (`$sentAt`) using the `notifyAt` method provided by the Snooze package. It requires the model to use the `SnoozeNotifiable` trait, a valid notification class, and a `Carbon` datetime object for the send time. ```php Auth::user()->notifyAt(new OneWeekAfterNotice(), $sentAt); ``` -------------------------------- ### Schedule Anonymous Notification - PHP Source: https://github.com/thomasjohnkane/snooze/blob/master/README.md This example demonstrates scheduling a notification to an anonymous target using the ScheduledNotification::create method. It uses an AnonymousNotifiable instance to specify routing information (e.g., email, SMS) without needing a dedicated model. ```php $target = (new AnonymousNotifiable) ->route('mail', 'hello@example.com') ->route('sms', '56546456566'); ScheduledNotification::create( $target, // Target new ScheduledNotificationExample($order), // Notification Carbon::now()->addDay() // Send At ); ``` -------------------------------- ### Scheduling Notifications on User Creation in PHP Source: https://github.com/thomasjohnkane/snooze/blob/master/docs/examples/on-boarding-email-drip.md This PHP function, intended for a Laravel User Observer's `created` method, demonstrates how to schedule a series of notifications for a new user. It uses the `notifyAt` method provided by the `SnoozeNotifiable` trait to schedule three distinct notifications at relative times (1 hour, 3 days, 1 week) from the user's creation time. It requires the `Carbon` library for time manipulation and the User model to have the `SnoozeNotifiable` trait. ```php // 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()); } ``` -------------------------------- ### Run Package Tests - Bash Source: https://github.com/thomasjohnkane/snooze/blob/master/README.md This command executes the automated tests for the laravel-snooze package using Composer. It's used by developers to ensure the package is functioning correctly. ```bash composer test ``` -------------------------------- ### Publish Snooze Configuration - Bash Source: https://github.com/thomasjohnkane/snooze/blob/master/README.md This command publishes the configuration file for the laravel-snooze package. This allows you to customize settings like the command scheduling frequency, send tolerance, and pruning age. ```bash php artisan vendor:publish --provider="Thomasjohnkane\Snooze\ServiceProvider" --tag="config" ``` -------------------------------- ### Adding SnoozeNotifiable Trait to User Model in PHP Source: https://github.com/thomasjohnkane/snooze/blob/master/docs/examples/on-boarding-email-drip.md This snippet shows how to add the `SnoozeNotifiable` trait to your Laravel User model. This trait provides the necessary methods, such as `notifyAt`, for scheduling notifications using the Snooze package. It is a required step to make your model capable of sending scheduled notifications. ```php use Thomasjohnkane\Snooze\Traits\SnoozeNotifiable; class User { use SnoozeNotifiable; } ``` -------------------------------- ### Test Laravel Scheduler Command - Bash Source: https://github.com/thomasjohnkane/snooze/blob/master/README.md This command manually runs the Laravel scheduler. It's used to test if your cron job or daemon is correctly triggering scheduled commands, including the `snooze:send` command. ```bash php artisan schedule:run ``` -------------------------------- ### Enable Laravel Scheduler onOneServer - Bash Source: https://github.com/thomasjohnkane/snooze/blob/master/README.md This environment variable setting enables Laravel's onOneServer feature for the snooze commands. This ensures that if you have multiple servers running the scheduler, the snooze commands will only be executed on one of them to prevent duplicate sends. ```bash SCHEDULED_NOTIFICATIONS_ONE_SERVER = true ``` -------------------------------- ### Store Meta Info with notifyAt Trait - PHP Source: https://github.com/thomasjohnkane/snooze/blob/master/README.md This snippet demonstrates how to store meta information using the notifyAt() method provided by the SnoozeNotifiable trait. The meta array is passed as an optional third argument to the method. ```php $user->notifyAt(new BirthdayNotification, Carbon::parse($user->birthday), ['foo' => 'bar']); ``` -------------------------------- ### Schedule Notification using ScheduledNotification Create - PHP Source: https://github.com/thomasjohnkane/snooze/blob/master/README.md This PHP snippet shows how to schedule a notification using the static create method on the ScheduledNotification model. It requires the target notifiable (like a user), the notification instance, and the Carbon instance for the desired send time. ```php ScheduledNotification::create( Auth::user(), // Target new ScheduledNotificationExample($order), // Notification Carbon::now()->addHour() // Send At ); ``` -------------------------------- ### Query Scheduled Notifications by Meta Info - PHP Source: https://github.com/thomasjohnkane/snooze/blob/master/README.md This snippet demonstrates how to query the database for scheduled notifications based on their stored meta information. The static findByMeta() helper method allows searching for notifications where a specific meta key has a certain value. ```php ScheduledNotification::findByMeta('foo', 'bar'); //key and value ``` -------------------------------- ### Schedule Notification using Trait - PHP Source: https://github.com/thomasjohnkane/snooze/blob/master/README.md This PHP code demonstrates how to schedule notifications on a Laravel model by using the SnoozeNotifiable trait. It adds a notifyAt() method to the model, allowing you to specify the notification class and the future Carbon instance for sending. ```php use Thomasjohnkane\Snooze\Traits\SnoozeNotifiable; use Illuminate\Notifications\Notifiable; class User extends Model { use Notifiable, 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')); ``` -------------------------------- ### Store Meta Info with ScheduledNotification Create - PHP Source: https://github.com/thomasjohnkane/snooze/blob/master/README.md This PHP code shows how to store additional meta information (as an associative array) when creating a scheduled notification using the ScheduledNotification::create helper method. The meta array is passed as the fourth argument. ```php ScheduledNotification::create( $target, // Target new ScheduledNotificationExample($order), // Notification Carbon::now()->addDay(), // Send At, ['foo' => 'bar'] // Meta Information ); ``` -------------------------------- ### Duplicate Scheduled Notification - PHP Source: https://github.com/thomasjohnkane/snooze/blob/master/README.md This code demonstrates how to create a new scheduled notification that is a duplicate of an existing one, but scheduled for a different time. It uses the scheduleAgainAt() method with a new Carbon instance. ```php $notification->scheduleAgainAt($newDate); // Returns the new (duplicated) $notification ``` -------------------------------- ### Retrieve Meta Info from Scheduled Notification - PHP Source: https://github.com/thomasjohnkane/snooze/blob/master/README.md This PHP code shows how to retrieve the stored meta information from an existing ScheduledNotification instance. The getMeta() method can retrieve the entire array or a specific value by providing a key. ```php // Retrieve the entire meta array $metaData = $notification->getMeta(); // Retrieve a specific value $fooValue = $notification->getMeta('foo'); ``` -------------------------------- ### Conditionally Interrupt Notification - PHP Source: https://github.com/thomasjohnkane/snooze/blob/master/README.md This PHP code demonstrates how to add a shouldInterrupt() method to a Laravel Notification class. This method is executed just before the scheduled notification is sent and can return true to prevent sending based on custom logic. ```php public function shouldInterrupt($notifiable) { return $notifiable->isInactive() || $this->order->isCanceled(); } ``` -------------------------------- ### Check if Notification is Cancelled - PHP Source: https://github.com/thomasjohnkane/snooze/blob/master/README.md This PHP code checks the status of a scheduled notification to see if it has been marked as cancelled. It calls the isCancelled() method on a ScheduledNotification instance. ```php $result = $notification->isCancelled(); // returns a bool ``` -------------------------------- ### Check if Notification is Sent - PHP Source: https://github.com/thomasjohnkane/snooze/blob/master/README.md This snippet checks whether a scheduled notification has already been sent. It calls the isSent() method on a ScheduledNotification instance and returns a boolean result. ```php $result = $notification->isSent(); // returns a bool ``` -------------------------------- ### Cancel Scheduled Notification - PHP Source: https://github.com/thomasjohnkane/snooze/blob/master/README.md This PHP code demonstrates how to cancel a previously scheduled notification. It calls the cancel() method on an existing ScheduledNotification instance, preventing it from being sent. ```php $notification->cancel(); ``` -------------------------------- ### Reschedule Scheduled Notification - PHP Source: https://github.com/thomasjohnkane/snooze/blob/master/README.md This snippet shows how to change the scheduled send time for a notification that has not yet been sent or cancelled. It calls the reschedule() method with a new Carbon instance representing the desired send time. ```php $rescheduleAt = Carbon::now()->addDay(1); $notification->reschedule($rescheduleAt); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.