Switch branches/tags
Clone or download
Latest commit 89b9f2f Apr 5, 2018
Failed to load latest commit information.
config Add support for VAPID Mar 25, 2017
migrations initial Aug 12, 2016
src Add notification options Nov 15, 2017
tests Apply fixes from StyleCI Nov 15, 2017
.editorconfig initial Aug 12, 2016
.gitattributes initial Aug 12, 2016
.gitignore Add tests Aug 14, 2016
.scrutinizer.yml Add code coverage (#9) Aug 16, 2016
.styleci.yml initial Aug 12, 2016
.travis.yml Don't test 7.2 yet Oct 23, 2017 Add notification options Nov 15, 2017 initial Aug 12, 2016 initial Aug 12, 2016 Update Apr 5, 2018
composer.json Add package discovery Oct 23, 2017
phpunit.xml.dist initial Aug 12, 2016

Web push notifications channel for Laravel

Latest Version on Packagist Software License Build Status StyleCI SensioLabsInsight Quality Score Code Coverage Total Downloads

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


You can install the package via composer:

composer require laravel-notification-channels/webpush

First you must install the service provider (skip for Laravel>=5.5):

// config/app.php
'providers' => [

Add the NotificationChannels\WebPush\HasPushSubscriptions trait to your User model:

use NotificationChannels\WebPush\HasPushSubscriptions;

class User extends Model
    use HasPushSubscriptions;

Next publish the migration with:

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

Run the migrate command to create the necessary table:

php artisan migrate

You can also publish the config file with:

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

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

php artisan webpush:vapid

This command will set VAPID_PUBLIC_KEY and VAPID_PRIVATE_KEYin your .env file.

These keys must be safely stored and should not change.

If you still want support Google Cloud Messaging set the GCM_KEY and GCM_SENDER_ID in your .env file.


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

use Illuminate\Notifications\Notification;
use NotificationChannels\WebPush\WebPushMessage;
use NotificationChannels\WebPush\WebPushChannel;

class AccountApproved extends Notification
    public function via($notifiable)
        return [WebPushChannel::class];

    public function toWebPush($notifiable, $notification)
        return (new WebPushMessage)
            ->body('Your account was approved!')
            ->action('View account', 'view_account');
            // ->data(['id' => $notification->id])
            // ->badge()
            // ->dir()
            // ->image()
            // ->lang()
            // ->renotify()
            // ->requireInteraction()
            // ->tag()
            // ->vibrate()

Save/Update Subscriptions

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

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

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

The $key and $token are optional and are used to encrypt your notifications. Only encrypted notifications can have a payload.

Delete Subscriptions

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

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



For a complete implementation with a Service Worker check this demo.

Browser Compatibility

See the Push API browser compatibility.


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


$ composer test


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


Please see CONTRIBUTING for details.



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