Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 394 Vote(s) - 3.59 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Is there a way to send FCM push notification to all the email address i have in my local database

#1
Well I'm setting up a database where user details would be stored using ionic as front end and lumen to make API calls. My concern is that can i send a push notification to all the people who are using my application using the email information that is in my database. Is it possible

Following is the code that i am trying to do :

public function send_notification_all(Request $request){

$this->validate($request, [
'title' => 'required|max:30|min:20',
'message' => 'required'
]);

$noti_title = $request->input('title');
$noti_body = $request->input('message');

$optionBuilder = new OptionsBuilder();
$optionBuilder->setTimeToLive(60*20);

$notificationBuilder = new PayloadNotificationBuilder($noti_title);
$notificationBuilder->setBody($noti_body)
->setSound('default');

$dataBuilder = new PayloadDataBuilder();
$dataBuilder->addData(['a_data' => 'my_data']);

$option = $optionBuilder->build();
$notification = $notificationBuilder->build();
$data = $dataBuilder->build();
$email = User::pluck('email')->toArray();
$downstreamResponse = FCM::sendTo($email, $option, $notification, $data);

$downstreamResponse->numberSuccess();
$downstreamResponse->numberFailure();
$downstreamResponse->numberModification();

if($downstreamResponse->numberSuccess() == 0 ){
return $this->errorResponse("unable to send notificaton to all",401);
}else {
return $this->successResponse(['msg' => 'message send successfully','successfull' => $downstreamResponse->numberSuccess(),'failures' => $downstreamResponse->numberFailure()]);
}
}

Just need the opinion that is it possible to do it in this way and do let me know if there is any mistake or the changes that i have to make in my code. Waiting for the Positive response and Guidance
Reply

#2
You **can't** send notifications using their email addresses.

You should save in your Database the fcm_token of every user who registers. I suggest using the following package and reading the docs in it: [Laravel-FCM][1]

You should also take care of refreshing the token if the device request so.


[1]:

[To see links please register here]

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through