xcoorp / laravel-webpush-notifications
Web Push Notifications channel for Laravel.
Installs: 1 197
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 123
Open Issues: 0
pkg:composer/xcoorp/laravel-webpush-notifications
Requires
- php: ^8.3
- illuminate/config: ^11|^12
- illuminate/container: ^11|^12
- illuminate/contracts: ^11|^12
- illuminate/notifications: ^11|^12
- illuminate/support: ^11|^12
- minishlink/web-push: ^9
Requires (Dev)
- laravel/pint: ^v1
- pestphp/pest: ^v3
This package is auto-updated.
Last update: 2025-10-02 09:42:19 UTC
README
WebPush - Laravel Notification Channel
This package makes it easy to send notifications using Web Push API
class InvoicePaidNotification extends Notification { // Trigger a specific notification event public function toWebPush($notifiable) { return (new WebPushMessage) ->title('Approved!') ->body('Your account was approved!') ->action('View account', 'view_account') ->options(['TTL' => 1000]); } }
Contents
Installation
The Web Push notification channel can be installed easily via Composer:
composer require xcoorp/laravel-webpush-notifications
Publishing Configuration and Migrations
After installing the package, you can publish the configuration file and migrations by running the following command:
php artisan vendor:publish --provider="NotificationChannels\WebPush\WebPushServiceProvider"
After publishing the migrations you should migrate your database:
php artisan migrate
After publishing the configuration file, you should configure the vapid keys in your .env file:
VAPID_PUBLIC_KEY=your-public-key VAPID_PRIVATE_KEY=your-private-key VAPID_SUBJECT=your-email or url
You can generate the vapid keys using the following command:
php artisan webpush-notifications:vapid
Configuration
The config/webpush-notifications.php configuration file allows you to configure the default Web Push options for your application.
You can define custom Models to use, and the vapid keys to use for the Web Push API.
If you define a custom UsereWebPushSubscription model you need to make sure it extends the UsereWebPushSubscription model shipped with this package.
Usage
In order to send a notification via the WebPush channel, you'll need to specify the channel in the via() method of your notification:
use NotificationChannels\WebPush\WebPushChannel; public function via($notifiable) { return [ WebPushChannel::class ] }
API Overview
WebPush Message
Namespace: NotificationChannels\WebPush\WebPushMessage
The WebPushMessage class encompasses an entire message that will be sent to the Web Push API.
title(string $title)Set thetitleof the messageaction(string $title, string $action, ?string $icon = null))Set theactionof the messagebadge(string $badge)Set the url to thebadgeimage of the messagebody(string $body)Set thebodyof the messagedir(string $dir)Set the text-directiondirof the messageicon(string $icon)Set the url to theiconof the messageimage(string $image)Set the url to theimageof the messagelang(string $lang)Set the Languagelangof the messagerenotify(bool $renotify)specifies whether the user should be notified after a new notification replaces an old onerequireInteraction(bool $requireInteraction)specifies whether the notification requires interactiontag(string $value)Set thetagof the messagevibrate(array $vibrate)Set the vibration patternvibrateof the messagedata(mixed $value)Set thedataof the messageoptions(array $options)Set theoptionsof the message (See here for more information)toArray()Returns the data that will be sent to the WebPush API as an array
Code of Conduct
In order to ensure that the community is welcoming to all, please review and abide by the Code of Conduct.
Security Vulnerabilities
Please review the security policy on how to report security vulnerabilities.
License
The MIT License (MIT). Please see License File for more information.