PHP code example of laravel-notification-channels / pubnub

1. Go to this page and download the library: Download laravel-notification-channels/pubnub library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

laravel-notification-channels / pubnub example snippets


// config/app.php
'providers' => [
    ...
    NotificationChannels\Pubnub\PubnubServiceProvider::class,
],

// config/services.php
...

'pubnub' => [
    'publish_key'   => env('PUBNUB_PUBLISH_KEY'),
    'subscribe_key' => env('PUBNUB_SUBSCRIBE_KEY'),
    'secret_key'    => env('PUBNUB_SECRET_KEY'),
],

... 

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

use Illuminate\Database\Eloquent\Model;
use Illuminate\Notifications\Notifiable;

class User extends Model
{
    use Notifiable;
    
    public function routeNotificationForPubnub()
    {
        return $this->pubnub_channel;
    }
}

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