0

I've implemented pusher beams like this:

  1. I've added credentials in config/services.php
'pusher' => [
  'beams_instance_id' => '********',
  'beams_secret_key' => '*************',
],
  1. I've created a new notification
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!");
    }


}

  1. I've added Notifiable to User Model :
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?

1
  • if any one could send some link to some tutorial Which implement pusher beams in laravel and react Nov 16, 2022 at 12:43

1 Answer 1

0
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",
        )),
        ));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.