kreait / laravel-firebase

A Laravel package for the Firebase PHP Admin SDK
https://github.com/kreait/firebase-php
MIT License
992 stars 163 forks source link

sendMulticast Not Working #127

Closed paradyo closed 2 years ago

paradyo commented 2 years ago

Send multicast not working at Laravel. My devices are handling the push but not the data inside. The data prop is always null when I use the sendMulticast function.

Can you please share simple demo code for sendMulticast?

I tried the one at firebase-php doc but that's not working at Laravel.

jeromegamez commented 2 years ago

Could you please share the code that you're using? It might help me to reproduce the problem 😅

paradyo commented 2 years ago

Could you please share the code that you're using? It might help me to reproduce the problem 😅

Ah, sorry. Here my code:

$tokens = ['abc', 'def']; $title = 'This is title!'; $desc = 'This is desc!'; Firebase::project('app')->auth(); $messagingInstance = Firebase::messaging(); $message = CloudMessage::new(); $message->withNotification(Notification::create($title, $desc)); $messagingInstance->sendMulticast($message, $tokens);

I deleted this code. And I solved with foreach the Single notification :(

Thanks.

jeromegamez commented 2 years ago

CloudMessages are immutable, you should replace

$message = CloudMessage::new();
$message->withNotification(Notification::create($title, $desc));

with

$message = CloudMessage::new();
$message = $message->withNotification(Notification::create($title, $desc));

or

$message = CloudMessage::new()
    ->withNotification(Notification::create($title, $desc));

https://firebase-php.readthedocs.io/en/stable/cloud-messaging.html would also be a good read

paradyo commented 2 years ago

CloudMessages are immutable, you should replace

$message = CloudMessage::new();
$message->withNotification(Notification::create($title, $desc));

with

$message = CloudMessage::new();
$message = $message->withNotification(Notification::create($title, $desc));

or

$message = CloudMessage::new()
    ->withNotification(Notification::create($title, $desc));

https://firebase-php.readthedocs.io/en/stable/cloud-messaging.html would also be a good read

It worked thankkss :))