Coder Social home page Coder Social logo

habibtalib / webpush Goto Github PK

View Code? Open in Web Editor NEW

This project forked from laravel-notification-channels/webpush

0.0 0.0 0.0 133 KB

Webpush notifications channel for Laravel.

Home Page: http://laravel-notification-channels.com

License: MIT License

PHP 100.00%

webpush's Introduction

Web push notifications channel for Laravel

Latest Version on Packagist Build Status Quality Score Code Coverage Total Downloads

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

Installation

You can install the package via composer:

composer require laravel-notification-channels/webpush

First 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 for Google Cloud Messaging, set the GCM_KEY and GCM_SENDER_ID in your .env file.

Usage

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)
            ->title('Approved!')
            ->icon('/approved-icon.png')
            ->body('Your account was approved!')
            ->action('View account', 'view_account')
            ->options(['TTL' => 1000]);
            // ->data(['id' => $notification->id])
            // ->badge()
            // ->dir()
            // ->image()
            // ->lang()
            // ->renotify()
            // ->requireInteraction()
            // ->tag()
            // ->vibrate()
    }
}

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:

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

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

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);

$user->deletePushSubscription($endpoint);

Browser Compatibility

See the Push API browser compatibility.

Changelog

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

Testing

$ 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

License

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

webpush's People

Contributors

cretueusebiu avatar freekmurze avatar joostdebruijn avatar alberto-bottarini avatar themsaid avatar themustafaomar avatar vesper8 avatar web-flow avatar codetheorist avatar bhulsman avatar briandotdev avatar casperboone avatar ikoolik avatar jadamec avatar japseyz avatar mpociot avatar jaybizzle avatar nmfzone avatar nonovd avatar oele-dev avatar oyed avatar patrickpietens avatar prakashchhetri avatar srustamov avatar pes8 avatar stylecibot avatar atymic avatar martijnb92 avatar michaellovescoke avatar snipe avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.