-
Notifications
You must be signed in to change notification settings - Fork 93
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
Message to multiple devices #2
Comments
How do you do this? Anyone solved? |
Did you tried
? |
I have done it like this and it works... My admin users can have subscription enabled on multiple devices... /** |
Apparently, the problem is in the Notifications concept in Laravel itself. When you send a notification you send it to one recipient (e.g. It's the same idea as @junaid-A-khan mentioned. But it's not a really convenient approach to define a special model for that. @benwilkins could you, please, comment this? Is there any way to send Notifications to multiple tokens without defining additional models and use a simple code like: Notification::send($devices, new SomeNotification(...)); |
That's a good question. The way I've done it is by creating device groups in FCM and sending to a group ID. |
@VladimirBerdnik The FcmMessage is designed to take only one recipient. This can be a device token, a device group token, or a topic. Passing an array will not work. If you're wanting to send to multiple recipients in one message, the best way to do it is to use FCM's topics or device groups. |
@benwilkins, the legacy FCM protocol is able to send a message to an array of device tokens, and this library seems to accommodate that functionality: laravel-fcm-notification/src/FcmMessage.php Lines 265 to 269 in 27c5a97
For this to work you need to return an array of device tokens from // User.php
public function fcmTokens()
{
return $this->hasMany(FcmToken::class);
// The FcmToken model uses the table `fcm_tokens` which looks like this:
//
// fcm_tokens
// --------------------------
// user_id (foreign key)
// token
}
public function routeNotificationForFcm()
{
// Return the tokens as an array
return $this->fcmTokens->pluck('token')->toArray();
} And this array is used by the FCM channel: laravel-fcm-notification/src/FcmChannel.php Lines 46 to 52 in 27c5a97
|
@nicoqh Ah you're right! I forgot about that. That was a PR submitted a while back. |
Can anyone give me a good explanation of how to send to bulk notification ? |
How to create a device group ? Is this package able to send notification to a device group? |
How to send message to multiple devices?
The text was updated successfully, but these errors were encountered: