laravel-notification-channels / pusher-push-notifications

Pusher Beams notifications channel for Laravel
http://laravel-notification-channels.com
MIT License
271 stars 67 forks source link

toPushNotification not trigger #82

Open NicoCascella opened 3 months ago

NicoCascella commented 3 months ago

I'm trying to use pusher-push-notifications in Laravel 11, with a Vue 3 SPA, in a separate project. If I try to make the call with a Curl or an Http request, the notification is successful. The problem arises when I try to use the pusher-push-notifications functionalities.

` $user = \App\Models\User::find(136); $notifica = 'notifica'; try { // $user->notify( new TestNotification($notifica)); \Illuminate\Support\Facades\Notification::send(User::all(), new TestNotification($notifica));

} catch (\Exception $e) {
    dd($e->getMessage());
}

<?php

namespace App\Notifications; use NotificationChannels\PusherPushNotifications\PusherChannel; use NotificationChannels\PusherPushNotifications\PusherMessage;

use Illuminate\Bus\Queueable; use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Notifications\Notification;

class TestNotification extends Notification { public $notifica; /**

` Basically, the notification's via() method doesn't lead me to the next toPushNotification and therefore doesn't send the notification. Does anyone have any solutions?

Mohammad-Yasin-Noori commented 3 months ago

use it as below, as in laravel 10 and 11 it is not triggering as in docs.


public function toPushNotification($notifiable)
    {
        $beamsClient = new \Pusher\PushNotifications\PushNotifications([
            'instanceId' => config('services.pusher.beams_instance_id'),
            'secretKey' => config('services.pusher.beams_secret_key'),
        ]);

        $publishResponse = $beamsClient->publishToInterests(
            ['App.User.'.$notifiable->id],
            ['web' => [
                'notification' => [
                    'title' => 'New Customer Registered!',
                    'body' => "{$this->customerName} has been registered to the system!",
                ],
            ],
            ]);

        return $publishResponse;
    }
SpyridonLaz commented 1 week ago

it does not work for me either and we need it in our company.

We are using laravel 11,livewire3 , pusher beams. Can you please copy-paste the whole code that is relative to beams (front-end,back-end) so as to see what's the right way? i would greatly appreciate it .

Spyridon

use it as below, as in laravel 10 and 11 it is not triggering as in docs.


public function toPushNotification($notifiable)
    {
        $beamsClient = new \Pusher\PushNotifications\PushNotifications([
            'instanceId' => config('services.pusher.beams_instance_id'),
            'secretKey' => config('services.pusher.beams_secret_key'),
        ]);

        $publishResponse = $beamsClient->publishToInterests(
            ['App.User.'.$notifiable->id],
            ['web' => [
                'notification' => [
                    'title' => 'New Customer Registered!',
                    'body' => "{$this->customerName} has been registered to the system!",
                ],
            ],
            ]);

        return $publishResponse;
    }