Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
W

webpush

> 后端框架
Open source

Webpush notifications channel for Laravel.

907 stars0 likes5 views
WebsiteGitHub

About

Webpush notifications channel for Laravel.

Web Push Notifications Channel for Laravel

This package makes it easy to send web push notifications with Laravel.

Features

  • Easy integration with Laravel notifications: Seamlessly integrates with Laravel's notification system, allowing you to send web push notifications using familiar notification channels.
  • Multiple browser support: Works with all major browsers that implement the Push API, including Chrome, Firefox, Edge, and Safari.
  • VAPID support: Easily generate and manage VAPID keys for secure browser authentication.
  • Flexible message options: Customize notifications with title, body, icon, actions, TTL, and more. Supports advanced options like vibration, badge, image, and custom data payloads.
  • Subscription management: Convenient methods to save, update, and delete push subscriptions directly on your notifiable models.
  • Automatic expired subscription cleanup: When sending a push message to an expired subscription, the package detects expired endpoints (using the expired flag of Minishlink\WebPush\MessageSentReport). This package will automatically delete expired subscriptions.
  • Configurable and extendable: Publish and customize the package's config file to fit your application's needs.

Installation

You can install the package via Composer:

bash
composer require laravel-notification-channels/webpush

First, add the NotificationChannels\WebPush\HasPushSubscriptions trait to your User model:

php
use NotificationChannels\WebPush\HasPushSubscriptions;

class User extends Model
{
    use HasPushSubscriptions;
}

Next, publish the migration with:

bash
php artisan vendor:publish --provider="NotificationChannels\WebPush\WebPushServiceProvider" --tag="migrations"

Run the migrate command to create the necessary table:

bash
php artisan migrate

Upgrading existing installations: If you installed this package before endpoint URLs were widened to 1024 characters, publish migrations again and run php artisan migrate to apply increase_push_subscriptions_endpoint_length. Some push services (for example Microsoft WNS) may generate endpoints longer than 500 characters.

You can also publish the config file with:

bash
php artisan vendor:publish --provider="NotificationChannels\WebPush\WebPushServiceProvider" --tag="config"

Generate the VAPID keys (required for browser authentication) with:

bash
php artisan webpush:vapid

This command will set VAPID_PUBLIC_KEY and VAPID_PRIVATE_KEY in your .env file. You need the VAPID_PUBLIC_KEY as applicationServerKey when using the Push API.

Note for Safari:

  • If targeting Safari or iOS (especially after 2023), you must include the VAPID_SUBJECT variable in your .env file. This should be a valid URL (e.g. https://example.com) or a mailto: address (e.g. mailto:[email protected]).
  • Apple will reject requests with a BadJwtToken error if VAPID_SUBJECT is missing or invalid.
  • The domain in VAPID_SUBJECT must be a valid, existing top-level domain (TLD).

These keys must be safely stored and should not change.

HTTP Client

On Laravel 13, push notifications use Laravel's HTTP client. Laravel 13.13 or later is required. This means global HTTP middleware, request logging, and Http::fake() also apply to web push requests. The package uses a 30-second timeout by default and passes the client_options from the published webpush configuration to the Laravel HTTP client.

Laravel 12 uses a Guzzle client with the same timeout and client_options configuration. This fallback is required because earlier Laravel HTTP clients cannot be safely used as PSR-18 clients.

Usage

Now you can use the channel in your via() method inside the notification and send a generic web push notification:

…

Declarative Web Push messages

Note: The specification for Declarative Web Push messages is still evolving and may change in the future. Browser support for this functionality is currently limited and may vary across platforms.

This package also supports Declarative Web Push messages, which aim to reduce the complexity of using push on the web in general and address some challenges of generic web push notifications like privacy concerns & battery life on mobile by making a client-side service worker optional while remaining fully backwards compatible:

…

You can find the available options here.

Save/Update Subscriptions

To save or update a subscription, use the updatePushSubscription($endpoint, $key = null, $token = null, $contentEncoding = null) method on your user:

php
$user = \App\User::find(1);

$user->updatePushSubscription($endpoint, $key, $token, $contentEncoding);

The $key and $token are optional and are used to encrypt your notifications. However, all major browsers require encryption when sending notifications.

When using the Push API, $key is the value of the getKey('p256dh') method, and $token is the value of the getKey('auth') method of the PushSubscription interface.

Delete Subscriptions

To delete a subscription, use the deletePushSubscription($endpoint) method on your user:

php
$user = \App\User::find(1);

$user->deletePushSubscription($endpoint);

Browser Compatibility

See the Push API browser compatibility.

Changelog

Please see CHANGELOG for more information about what has changed recently.

Testing

bash
composer test

Security

If you discover any security-related issues, please email [email protected] instead of using the issue tracker.

Contributing

Please see CONTRIBUTING for details.

Credits

  • Cretu Eusebiu
  • All Contributors

License

The MIT License (MIT). Please see License File for more information.

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

PHPlaravelnotificationswebpush

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category后端框架
PricingOpen source

> Related tools

N
Node.js
基于 V8 的 JavaScript 运行时
D
Django
Python 高级 Web 框架
S
Spring Boot
Java 生态主流微服务框架