Downloads
Stars
Version
This package makes it easy to send Pusher push notifications with Laravel (should work with other non-laravel PHP projects). It's based off this package by Mohamed Said.
This fork exists to allow us to run both the Pusher Beams and old Pusher Channels code side by side.
You can install the package via composer:
composer require rich2k/pusher-beams
You must install the service provider:
// config/app.php
'providers' => [
...
Rich2k\PusherBeams\PusherBeamsServiceProvider::class,
],
Before using this package you should set up a Pusher account. Here are the steps required.
config/broadcasting.php
file under the pusher connection, see below.In config/broadcasting.php
'connections' => [
...
'pusher' => [
'beams' => [
'secret_key' => env('PUSHER_BEAMS_SECRET'),
'instance_id' => env('PUSHER_BEAMS_INSTANCE_ID'),
],
],
],
Now you can use the channel in your via()
method inside the Notification
class.
use Rich2k\PusherBeams\PusherBeams;
use Rich2k\PusherBeams\PusherBeamsMessage;
use Illuminate\Notifications\Notification;
class AccountApproved extends Notification
{
public function via($notifiable)
{
return [PusherBeams::class];
}
public function toPusherBeamsNotification($notifiable)
{
return PusherBeamsMessage::create()
->iOS()
->badge(1)
->sound('success')
->body("Your {$notifiable->service} account was approved!");
}
}
platform('')
: Accepts a string value of iOS
or Android
.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 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. For more information check here for iOS, or here for Android.withiOS(PusherBeamsMessage $message)
: Set an extra message to be sent to iOSwithAndroid(PusherBeamsMessage $message)
: Set an extra message to be sent to AndroidYou can send a single message to an iOS device and an Android device at the same time using the withiOS()
and withAndroid()
method:
use Rich2k\PusherBeams\PusherBeams;
use Rich2k\PusherBeams\PusherBeamsMessage;
use Illuminate\Notifications\Notification;
class AccountApproved extends Notification
{
public function via($notifiable)
{
return [PusherBeams::class];
}
public function toPusherBeamsNotification($notifiable)
{
return PusherBeamsMessage::create()
->android()
->sound('success')
->body("Your {$notifiable->service} account was approved!")
->withiOS(PusherBeamsMessage::create()
->body("Your {$notifiable->service} account was approved!")
->badge(1)
->sound('success')
);
}
}
By default the Pusher beams "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.
Whatever interest you set in the app is the interest you should register for within your mobil
$ composer test
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
Please see CONTRIBUTING for details.
The MIT License (MIT). Please see License File for more information.