This is a fork of https://github.com/wanghanlin/pusher-push-notifications which suggests changes to the original project https://github.com/laravel-notification-channels/pusher-push-notifications which are not updated.
This package makes it easy to send Pusher push notifications with Laravel 5.5 and 5.6. If you are using Laravel 5.3 or 5.4, use 1.x branch. Since pusher dropped the support of API key and secret for push notification on new projects created on https://dashboard.pusher.com in favor of new https://dash.pusher.com, this package only support the latest version of pusher push notifications.
You can install the package via composer:
composer require laravel-notification-channels/pusher-push-notifications
Before using this package you should set up a Pusher account. Here are the steps required.
- Login to https://dash.pusher.com/
- Add a new instance in Push Notifications service.
- Upload your APNS Certificate or add your GCM API key.
- Now select your instance in left navigation area.
- Copy your
instance_id
, andsecret
. - Update the values in your
config/broadcasting.php
file under the pusher connection with namepush_notification_instance_id
andpush_notification_secret
- You're now good to go.
In config/broadcasting.php
, it should looks like this
'connections' => [
'pusher' => [
'push_notification_instance_id' => 'YOUR INSTANCE ID HERE', // Looks like a uuid
'push_notification_secret' => "YOUR SECRET HERE", // 31 char string
],
],
Now you can use the channel in your via()
method inside the Notification class.
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!");
}
}
platform('')
: Accepts a string value ofiOS
orAndroid
.iOS()
: Sets the platform value to iOS.android()
: Sets the platform value to Android.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 bedefault
.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. For more information check here for iOS, or here for Android.
You can send a single message to an iOS device and an Android device at the same time using the withiOS()
and withAndroid()
method:
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()
orwithiOS()
you don't have to define the platform, it's done behind the scenes for you.
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 routeNotificationForPusherPushNotifications()
in the notifiable class method that returns the interest name.
Please see CHANGELOG for more information what has changed recently.
$ composer test
If you discover any security related issues, please email themsaid@gmail.com instead of using the issue tracker.
Please see CONTRIBUTING for details.
The MIT License (MIT). Please see License File for more information.