gg-innovative / larafirebase

MIT License
21 stars 5 forks source link

How to send notification to multiple devices #2

Open SayedAbbady opened 6 months ago

SayedAbbady commented 6 months ago

In the previous package, it was possible to provide an array of tokens and firebase would send a notification to each one, but in this package, it only allows to accept 1 token as a string and not an array.

larafirebase]

jonth93 commented 4 months ago

device_tokens as castable array on user model.

$deviceTokens = $notifiable->device_tokens;

        foreach ($deviceTokens as $t) {
            Larafirebase::withTitle('Test Notification')
                ->withBody('I have something new to share with you!')
                ->withImage('https://firebase.google.com/images/social.png')
                ->withToken($t)
                ->sendNotification();
        }
Maschga commented 2 months ago

Hi, in the last repository this was possible, because Firebase supported sending multiple tokens in the request-Body. However, this api has been discontinued. They now advice to iterate through your list of tokens and to send a request for each token: https://firebase.google.com/docs/cloud-messaging/send-message?hl=de#send-messages-to-multiple-devices