benwilkins / laravel-fcm-notification

Laravel FCM (Firebase Cloud Messaging) Notification Channel
MIT License
213 stars 91 forks source link

How to send all device that have my app installed? #39

Open syahnur197 opened 5 years ago

syahnur197 commented 5 years ago

So far what I understand this package can help me to send notification to specific user(s). So we need to query all the users in the db and send the notification individually to them. My problem right now is, I want to send FCM notification to all devices that installed my app. How can I do that in Laravel?

I tried on demand notification but it didn't work

Notification::(new PromotionNotification($promotion));

Using the method above, I need to chain with route()

Notification::route('fcm', 'insert device token here')->notify(new InvoicePaid($invoice));

However, this is not what I want to achieve, since I need to specify the users again to use the above method.

PeterDanielso commented 5 years ago

Hello, im trying to reach similar behaviour. As far as i know, notifications have options to send notifications to many users with something like this:

$users = User::whereHas('if_your_user_has_device_fcm_tokens_logic')->get(); Notification::send($users, new YourFcmNotification($anyData));

Maybe something like that fit our requirements sending notifications to all users who have installed the app and also enabled to send token to your server.

flexgrip commented 4 years ago

No, from the cloud messaging console, we can choose an app as a target. Like, "Send to all iOS". So there must be a similar way to do it via the api... just may not be implemented in this package.

I see that you can send via a topic. I'll dig through it and see if there's a way to send to a targeted app.

PeterDanielso commented 4 years ago

Okey, thanks for explanation. That would have less impact on laravel server same as when broadcasting client messages. I will be looking for news, glad to improve things if need help.

On our personal case we need some kind of syncro, i mean, when we send fcm notifications we also clone it to laravel and later we link the fcm url to that laravel notification then users do actions with them (mark them read bla bla).

Hope my english is understandable. Have good day.