laravel-notification-channels/webpush
Laravel notification channel for sending Web Push notifications. Supports VAPID keys, major browsers, rich payload options (title, actions, data, TTL), and easy subscription management on models with automatic cleanup of expired endpoints.
Notification facade. It extends the existing via() method pattern, requiring minimal architectural changes.HasPushSubscriptions trait enables polymorphic usage across multiple models (e.g., User, Device, or custom Notifiable models).NotificationSent, NotificationFailed) for observability and extensibility, aligning with Laravel’s event system.WebPushMessage and experimental Declarative Web Push (W3C standard), allowing TPMs to choose based on browser support and feature requirements.VAPID_SUBJECT).VAPID_SUBJECT (valid domain/email) and may reject requests without it (e.g., BadJwtToken errors). Requires testing on real devices..env is a risk; consider environment-specific key management.ReportHandler) is enabled by default but may need tuning for high-volume apps (e.g., batch processing).NotificationFailed events for throttling.VAPID_SUBJECT configured and tested?WebPushMessage be the primary channel, with Declarative Web Push as an opt-in feature?NotificationSent/NotificationFailed events being logged/monitored? What’s the SLA for handling failed notifications?Mail, Slack).bus:queue) will work as expected.NotificationTestCase and PHPUnit; easy to mock in tests.navigator.serviceWorker.register('/sw.js').then(reg => {
reg.pushManager.subscribe({ userVisibleOnly: true })
.then(sub => fetch('/api/subscribe', { method: 'POST', body: JSON.stringify(sub) }));
});
self.addEventListener('push', event => {
event.waitUntil(clients.matchAll({ type: 'window' }).then(clients => {
clients.forEach(client => client.postMessage(event.data.json()));
}));
});
80/443 if sending to custom domains.php artisan webpush:vapid).HasPushSubscriptions trait to target models (e.g., User).config/webpush.php (e.g., padding, TTL, VAPID_SUBJECT for Safari)./api/subscribe).Notification.WebPushChannel and WebPushMessage/DeclarativeWebPushMessage.php artisan notify:test (if using Laravel’s testing helpers).NotificationSent/NotificationFailed.VAPID_SUBJECT).VAPID_SUBJECT requirements.// app/Console/Commands/CleanupExpiredSubscriptions.php
use NotificationChannels\WebPush\Events\SubscriptionExpired;
protected function handle() {
event(new SubscriptionExpired());
// Or use a queue job for async processing.
}
web-push-php library is actively maintained (v10+). Monitor for breaking changes (e.g., encryption defaults in v11.0.0).BadJwtToken (missing VAPID_SUBJECT), InvalidTtl (TTL too large).NotificationFailed events to log errors.How can I help you explore Laravel packages today?