### Install Package via Composer Source: https://github.com/humweb/notification-subscriptions/blob/main/docs/installation.md Installs the humweb/notification-subscriptions package using Composer. This is the primary method for adding the package to your project. ```bash composer require humweb/notification-subscriptions ``` -------------------------------- ### Publish and Run Migrations Source: https://github.com/humweb/notification-subscriptions/blob/main/docs/installation.md Publishes the package's migration files and then runs them to create the necessary database tables (`notification_subscriptions` and `pending_notifications`). ```bash php artisan vendor:publish --tag="notification-subscriptions-migrations" php artisan migrate ``` -------------------------------- ### Install Notification Subscriptions Source: https://github.com/humweb/notification-subscriptions/blob/main/README.md Installs the notification-subscriptions package using Composer. This is the primary step to integrate the package into your Laravel project. ```bash composer require humweb/notification-subscriptions ``` -------------------------------- ### Publish Configuration File Source: https://github.com/humweb/notification-subscriptions/blob/main/docs/installation.md Publishes the package's configuration file to your project's config directory, allowing for customization of settings. ```bash php artisan vendor:publish --tag="notification-subscriptions-config" ``` -------------------------------- ### Laravel Digest Notification Class Example Source: https://github.com/humweb/notification-subscriptions/blob/main/docs/usage/digest-system.md Provides a complete example of a Laravel Notification class (`UserNotificationDigest`) that handles the formatting and sending of digest notifications. It includes methods for sending via email (`toMail`) and as an array (`toArray`), along with constructor logic to accept the channel and pending notification data. ```php namespace App\Notifications; use Illuminate\Bus\Queueable; use Illuminate\Notifications\Notification; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Support\Collection; class UserNotificationDigest extends Notification implements ShouldQueue { use Queueable; public string $channel; public Collection $pendingNotificationsData; public function __construct(string $channel, Collection $pendingNotificationsData) { $this->channel = $channel; $this->pendingNotificationsData = $pendingNotificationsData; } public function via($notifiable): array { // Send the digest via the channel it was originally intended for return [$this->channel]; } public function toMail($notifiable): MailMessage { $mailMessage = (new MailMessage) ->subject('Your Notification Digest'); if ($this->pendingNotificationsData->isEmpty()) { $mailMessage->line('You have no new notifications in this digest period.'); return $mailMessage; } $mailMessage->line('Here is a summary of your notifications:'); foreach ($this->pendingNotificationsData as $item) { // Customize how each item in the digest is displayed // $item['class'] is the original notification class // $item['data'] contains the original constructor arguments for that notification // $item['created_at'] is when the original notification was triggered $mailMessage->line("---" ({$item['created_at']->format('M d, H:i')}) ---"); $mailMessage->line("Type: {$item['class']}"); // Example // You might want to load $item['data'] into the original notification class // and call a ->toDigestMail() method on it, or format data directly. $dataString = implode(', ', array_map(fn($k, $v) => "$k: " . (is_object($v) || is_array($v) ? json_encode($v) : $v), array_keys($item['data']), $item['data'])); $mailMessage->line("Details: {$dataString}"); } return $mailMessage; } public function toArray($notifiable): array { return [ 'message' => 'You have new notifications in your digest.', 'count' => $this->pendingNotificationsData->count(), 'items' => $this->pendingNotificationsData->map(function ($item) { return [ 'original_class' => $item['class'], 'data' => $item['data'], 'triggered_at' => $item['created_at']->toIso8601String(), ]; })->all(), ]; } } ``` -------------------------------- ### Vue Component for Notification Settings UI Source: https://github.com/humweb/notification-subscriptions/blob/main/docs/frontend-example.md An example Inertia-Vue component for displaying and managing user notification settings. It uses the data passed from the controller to render forms for subscribing/unsubscribing and configuring digest intervals. ```html