Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

Send push notification to all users #1

Closed
yaofong opened this issue Jul 7, 2016 · 2 comments
Closed

Send push notification to all users #1

yaofong opened this issue Jul 7, 2016 · 2 comments

Comments

@yaofong
Copy link

yaofong commented Jul 7, 2016

Hi,

Thanks for this amazing plugin.

Would like to know how do I push notifications to all users using my app?

@brozot
Copy link
Owner

brozot commented Jul 7, 2016

Hello thank's for your question.

Get all your tokens in your database and put them in a array
And send notifications with the Facade and the method FCM::sendTo(arrayOfTokens, options, notification, data)

Following a example that I have used in my app:

$tokens = Device::pluck('fcm_token')->toArray(); // Device is a Eloquent model that contains tokens

$optionBuilder = new OptionsBuilder();
$optionBuilder->setCollapseKey('cat_detected');

$notification = new PayloadNotificationBuilder(null);
$notification->setIcon('cat_notification')
                     ->setSound('default');

$notification->setTitleLocationKey('notification__title__cat_detected');
$notification->setBodyLocationKey('notification__body__cat_detected');
$notification->setBodyLocationArgs("[\"$detectionDate\", \"$detectionHour\"]");

$response = FCM::sendTo($tokens, $optionBuilder->build(), $notification->build());

I hope this answer will help you, and please not hesitate to contact me again if it's not working for you.

@macias67
Copy link

macias67 commented Oct 26, 2016

Hi, this way is an asynchronous method? Actually I use this in an event in Laravel 5.2, what do you think?

actmkan pushed a commit to actmkan/Laravel-FCM that referenced this issue Mar 3, 2021
actmkan pushed a commit to actmkan/Laravel-FCM that referenced this issue Mar 3, 2021
pc-magas pushed a commit to etablegr/Laravel-FCM that referenced this issue Oct 18, 2022
pc-magas pushed a commit to etablegr/Laravel-FCM that referenced this issue Oct 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants