I've implemented pusher beams like this:
config/services.php
'pusher' => [
'beams_instance_id' => '********',
'beams_secret_key' => '*************',
],
class TestOne extends Notification
{
use Queueable;
public $message;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct($message)
{
$this->message = $message;
}
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
return [PusherChannel::class , 'database'];
}
/**
* Get the array representation of the notification.
* @param mixed $notifiable
* @return array
*/
public function toArray($notifiable)
{
// event( new PostLiked($notifiable->id ,$this->message));
return [
'title' => $this->message->title,
'content' => $this->message->content,
];
}
// notification type
public function broadcastType()
{
return 'users';
}
public function toPushNotification($notifiable)
{
return PusherMessage::create()
->platform('web')
->badge(1)
->sound('success')
->body("Your ac account was approved!");
}
}
class User extends Authenticatable
{
use HasApiTokens, HasFactory, Notifiable;
How to specify the interest in my backend so I can listen to it in my react app and how to use beams debug console to make sure the Laravel notification is being fired?
public function toPushNotification($notifiable)
{
return PusherMessage::create()
->platform('web')
->badge(1)
->sound('success')
->body("Your ac account was approved!");
}
While I was tracking this code , It seems that I had a certificate issues problem in my local environment.
So I moved to this way in connection to beams :
$beamsClient = new \Pusher\PushNotifications\PushNotifications(array(
"instanceId" => "*********************************",
"secretKey" => "***************",
), new GuzzleHTTP\Client(['verify' => false]));
$publishResponse = $beamsClient->publishToUsers(
array("user-001", "user-002", "1"),
array("web" => array("notification" => array(
"title" => "fofo",
"body" => "Hello, World!",
"deep_link" => "https://www.pusher.com",
)),
));