laravel-notification-channels/pubnub
| Install | |
|---|---|
composer require laravel-notification-channels/pubnub |
|
| Latest Version: | 1.1.0 |
| PHP: | >=7.1 |
| License: | MIT |
| Last Updated: | Jul 1, 2021 |
| Links: | GitHub · Packagist |
PubNub Notifications Channel for Laravel
PubNub Notifications Channel for Laravel 5.5+ & 6.0. This channel allows you to send message payloads as well as push notifications to iOS, Android and Windows using PubNub.
Contents
Installation
composer require laravel-notification-channels/pubnub
Add the service provider to your config/app.php
// config/app.php
'providers' => [
...
NotificationChannels\Pubnub\PubnubServiceProvider::class,
],
Setting up the PubNub service
Add your PubNub Publish Key, Subscribe Key and Secret Key to your config/services.php
// config/services.php
...
'pubnub' => [
'publish_key' => env('PUBNUB_PUBLISH_KEY'),
'subscribe_key' => env('PUBNUB_SUBSCRIBE_KEY'),
'secret_key' => env('PUBNUB_SECRET_KEY'),
],
...
Usage
use NotificationChannels\Pubnub\PubnubChannel;
use NotificationChannels\Pubnub\PubnubMessage;
use Illuminate\Notifications\Notification;
class InvoicePaid extends Notification
{
public function via($notifiable)
{
return [PubnubChannel::class];
}
public function toPubnub($notifiable)
{
return (new PubnubMessage())
->channel('my_channel')
->title('My message title')
->body('My message body');
}
}
Alternatively you may supply a channel specifically related to your notifiable by implementing the routeNotificationForPubnub() method.
use Illuminate\Database\Eloquent\Model;
use Illuminate\Notifications\Notifiable;
class User extends Model
{
use Notifiable;
public function routeNotificationForPubnub()
{
return $this->pubnub_channel;
}
}
Sending a push notification. You may chain any of the withiOS(), withAndroid() and withWindows() methods to add push notifications to the message with each of the platforms.
use NotificationChannels\Pubnub\PubnubChannel;
use NotificationChannels\Pubnub\PubnubMessage;
use Illuminate\Notifications\Notification;
class InvoicePaid extends Notification
{
public function via($notifiable)
{
return [PubnubChannel::class];
}
public function toPubnub($notifiable)
{
return (new PubnubMessage())
->channel('my_channel')
->title('Alert: Jon Doe Sent You A Message')
->body('Hi')
->withiOS(
(new PubnubMessage())
->sound('default')
->badge(1)
)
->withAndroid(
(new PubnubMessage())
->sound('notification')
->icon('myicon')
)
->withWindows(
(new PubnubMessage())
->type('toast')
->delay(450);
);
}
}
Available methods
channel(''): Specifies the channel the message should be sent totitle(''): Sets the title of the messagebody(''): Sets the body of the messagestoreInHistory(true): If the message should be stored in the Pubnub historybadge(1): Sets the number to display on the push notification's badge (iOS)sound(''): Sets the sound for the push notification (iOS, Android)icon(''): Sets the push notification icon (Android)type(''): Sets the type of push notification (Windows)delay(450): Sets the delay in seconds for the push notification (Windows)setData($key, $value): Adds any extra data to the payload you may needsetOption($key, $value): Sets any option to the push notification (iOS, Android, Windows)withiOS(PubnubMessage $message): Sets the push notification for iOSwithAndroid(PubnubMessage $message): Sets the push notification for AndroidwithWindows(PubnubMessage $message): Sets the push notification for Windows
Changelog
Please see CHANGELOG for more information what has changed recently.
Testing
$ composer test
Security
If you discover any security related issues, please email wade@iwader.co.uk 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.
Related Packages
Powerful PHP database abstraction layer (DBAL) with many features for database s...
Laravel Serializable Closure provides an easy and secure way to serialize closur...
Cli error handling for console/command-line PHP applications.
Version History
| Version | Released | PHP | Laravel | License |
|---|---|---|---|---|
| 1.1.0 | >=7.1 | ~5.5 | | MIT |