Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

toPushNotification not trigger #82

Open
NicoCascella opened this issue Jun 6, 2024 · 3 comments
Open

toPushNotification not trigger #82

NicoCascella opened this issue Jun 6, 2024 · 3 comments

Comments

@NicoCascella
Copy link

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());
}

notifica = $notifica; } /** * Get the notification's delivery channels. * * @return array */ public function via(object $notifiable): array { return [PusherChannel::class ]; } public function toPushNotification($notifiable) { return PusherMessage::create() ->web() ->link(env('SPA_URL')) ->title('Titolo notifica') ->sound('success') ->body("Your {$notifiable->service} account was approved!"); } } ` 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
Copy link

Mohammad-Yasin-Noori commented Jun 26, 2024

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
Copy link

SpyridonLaz commented Sep 23, 2024

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;
    }

@molnarerwin
Copy link

Well my problem was that the documentation is misleading.

It says the default convention is App.User.1 while actually it's (at least for me) App.Models.User.1.

If in doubt just dd() the return of the defaultName method inside the PusherChannel.php.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants