Appearance
Notification Examples
The admin panel at admin/notifications/emails/{uri} shows rendered previews of notifications grouped by directory.
How it works
- A notification is sent → Laravel fires
NotificationSent CacheNotificationContentlistener builds a MailViewModel/SmsViewModel and saves it to disk- Admin visits the panel → controller finds notification classes in the matching directory, reads their cached ViewModels, renders them via a presenter, and outputs HTML
Only notifications implementing the ShouldCacheContent marker interface participate.
Key classes
| Responsibility | Class |
|---|---|
| Find notification classes by directory | Notifications\Support\Finder\ComposerAutoloadNotificationClassFinder |
| Cache on send (queued listener) | Modules\Notification\Listeners\CacheNotificationContent |
| Build ViewModel from notification | Modules\Notification\CachedContent\Factory\DefaultNotificationViewModelFactory |
| Store/retrieve ViewModels on disk | Modules\Notification\CachedContent\Store\FilesystemNotificationCachedContentStore |
| Render ViewModel to HTML | Modules\Notification\CachedContent\Presenter\DefaultNotificationViewModelPresenter |
| Generate admin panel links from FQCN | Modules\Notification\CachedContent\NotificationCachedContentLink |
Adding a notification to the panel
- Implement
ShouldCacheContenton the notification (or extendMailNotification/InAppNotificationwhich already implement it) - Add metadata attributes (
TriggerMode,TriggerConditions, etc.) - Send it once to populate the cache (see below)
Creating an example
The cache is populated by the CacheNotificationContent listener whenever a notification is actually sent. The easiest way to trigger this locally is via Tinker:
php
// 1. Pick a member to act as recipient
$member = \App\Modules\Member\Models\Member::find(1);
// 2. Instantiate the notification with its required dependencies
$enrollment = $member->courseEnrollments()->first();
$notification = new \App\Notifications\Course\Enrollment\CourseCertificateGenerated($enrollment);
// 3. Send it — the CacheNotificationContent listener will fire automatically
$member->notify($notification);After sending, the cached example appears on the matching admin panel page (e.g. admin/notifications/emails/course/enrollment).