2017 © Pedro Peláez
 

library pusher-push-notifications

Pusher native Push Notifications driver.

image

laravel-notification-channels/pusher-push-notifications

Pusher native Push Notifications driver.

  • Sunday, February 18, 2018
  • by laravel-notification-channels
  • Repository
  • 10 Watchers
  • 161 Stars
  • 11,230 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 38 Forks
  • 7 Open issues
  • 8 Versions
  • 5 % Grown

The README.md

Pusher Beams push notifications channel for Laravel 8.x & 9.x

Latest Version on Packagist Software License Build Status StyleCI SensioLabsInsight Quality Score Code Coverage Total Downloads, (*1)

This package makes it easy to send Pusher Beams push notifications with Laravel., (*2)

Please note that this notification channel should not be confused with Pusher Channels., (*3)

Also please note that prior to version 2.0, this package integrated with Pusher's beta push notifications service that was part of Pusher Channels. Please see Pusher's migration guide for more information., (*4)

Contents

Installation

You can install the package via composer:, (*5)

composer require laravel-notification-channels/pusher-push-notifications

Setting up your Pusher account

Before using this package you should set up a Pusher Beams account. Here are the steps required., (*6)

  • Login to https://dash.pusher.com/
  • Select the "Beams" product.
  • Select your instance from the list or create a new instance.
  • Click on the "Settings" tab.
  • Upload your APNS Certificate and/or add your FCM Server key.
  • Now select the "Keys" tab.
  • Copy your Instance Id, and Secret Key.
  • Add a new entry to in your config/services.php file: php 'pusher' => [ 'beams_instance_id' => 'Your Instance Id', 'beams_secret_key' => 'Your Secret Key', ],
  • You're now good to go.

Usage

Now you can use the channel in your via() method inside the Notification class., (*7)

use NotificationChannels\PusherPushNotifications\PusherChannel;
use NotificationChannels\PusherPushNotifications\PusherMessage;
use Illuminate\Notifications\Notification;

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

    public function toPushNotification($notifiable)
    {
        return PusherMessage::create()
            ->iOS()
            ->badge(1)
            ->sound('success')
            ->body("Your {$notifiable->service} account was approved!");
    }
}

Available Message methods

  • platform(''): Accepts a string value of iOS, Android or web.
  • iOS(): Sets the platform value to iOS.
  • android(): Sets the platform value to Android.
  • web(): Sets the platform value to web.
  • link(): Accepts a string value which will lead to URI specified on notification click.
  • title(''): Accepts a string value for the title.
  • body(''): Accepts a string value for the body.
  • sound(''): Accepts a string value for the notification sound file. Notice that if you leave blank the default sound value will be default.
  • icon(''): Accepts a string value for the icon file. (Android Only)
  • badge(1): Accepts an integer value for the badge. (iOS Only)
  • setOption($key, $value): Allows you to set any value in the message payload. See the request body section of the Pusher Beam docs for more information.

Sending to multiple platforms

You can send a single message to an iOS device and an Android device at the same time using the withiOS() and withAndroid() method:, (*8)

public function toPushNotification($notifiable)
{
    $message = "Your {$notifiable->service} account was approved!";

    return PusherMessage::create()
        ->iOS()
        ->badge(1)
        ->body($message)
        ->withAndroid(
            PusherMessage::create()
                ->title($message)
                ->icon('icon')
        );
}
  • Notice that iOS is the default platform, which means you don't have to call ->iOS().
  • When using withAndroid(), withiOS() or withWeb() you don't have to define the platform, it's done behind the scenes for you.

Routing a message

By default, the pusher "interest" messages will be sent to will be defined using the {notifiable}.{id} convention, for example App.User.1, however you can change this behaviour by including a routeNotificationFor() in the notifiable class., (*9)

I.e. if you are pushing notification on User model, you can go to App\Models\User class and implement method:, (*10)

public function routeNotificationForPusherPushNotifications($notification): string
{
    return 'your.custom.interest.string';
}

PusherPushNotifications() in the notifiable class method returns the interest name., (*11)

Publish to users

You can publish to users in the same way that you publish to interests but you must add the following variable to the notifiable model:, (*12)

class Client extends Model
{
    use Notifiable;

    public $pushNotificationType = 'users';
}

Changelog

Please see CHANGELOG for more information what has changed recently., (*13)

Testing

$ composer test

Security

If you discover any security related issues, please email themsaid@gmail.com instead of using the issue tracker., (*14)

Contributing

Please see CONTRIBUTING for details., (*15)

Credits

License

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

The Versions

10/08 2016