Briefing

Laravel Web Push Notifications – Add Push Support to Your Laravel App

ux
by Yannick Lyn Fatt · Laravel Composer

Add the laravel-notification-channels/webpush package, publish its migration, generate VAPID keys, and register the HasPushSubscriptions trait on your User model to enable web push notifications.

What to do now

Install the package, publish its migration, generate VAPID keys, add the HasPushSubscriptions trait to your User model, and configure a service worker to handle push events.

Summary

Laravel’s Notification Channels now include a Web Push Notifications Channel that plugs directly into Laravel’s notification system, allowing developers to send push alerts without a native app. The package adds a HasPushSubscriptions trait for the User model, publishes a migration to store subscription data, and provides a command to generate VAPID key pairs that are stored in the .env file. Safari users must also set a VAPID_SUBJECT URL or mailto: address to avoid BadJwtToken errors. The client side requires a service worker (sw.js) that listens for push and notificationclick events, and a meta tag exposing the VAPID public key to the browser. Subscriptions are managed via updatePushSubscription() and deletePushSubscription(), with the package automatically cleaning expired endpoints. Developers can send notifications by adding WebPushChannel to the via() method of a notification class and building a WebPushMessage, or by using DeclarativeWebPushMessage for the newer declarative push spec.

The package supports Chrome, Firefox, Edge, and Safari, works only over HTTPS (localhost is exempt), and includes optional features such as TTL, badge, vibrate, and action URLs. It integrates seamlessly with Laravel’s notification system, making push notifications as easy to send as email or Slack.

To get started, install the package via Composer, publish its migration and config, generate VAPID keys, add the HasPushSubscriptions trait to your User model, and register a service worker that handles push events and notification clicks.

Key changes

  • Adds WebPushChannel to Laravel notifications
  • Provides HasPushSubscriptions trait for User model
  • Publishes migration for subscriptions table
  • Generates VAPID key pair via php artisan webpush:vapid
  • Requires VAPID_SUBJECT for Safari to avoid BadJwtToken
  • Automatically removes expired subscriptions
  • Supports DeclarativeWebPushMessage for declarative push
  • Enforces HTTPS except localhost

Affects

internal

Customer impact

Analyzing matches…

Ask about this story

Impact on an agency? Which customers? Compare historically Risks of waiting