benwilkins / laravel-fcm-notification

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

FCM response in a Controller #74

Closed asiermusa closed 3 years ago

asiermusa commented 3 years ago

Hi!

It is possible to get the fcm response in the controller with API routes?

{
    "multicast_id": "number",
    "success": "number",
    "failure": "number",
    "canonical_ids": "number",
    "results": "array"
 }

My controller:

$fcm_response = Notification::send($user, new someNotification());
return response()->json([
    'fcm_response' => $fcm_response
]);

The $fcm_response always is null, and I tried with Laravel Notification Events. With listeners I was able to catch the response in my laravel.log but not to send it as api call response param.

<?php
namespace App\Listeners;
...
class NewNotificationListener
{
   public function handle(NotificationSent $event)
  {
      Log:info('Notification Listener:'.' '.var_dump($event));
   } 
}

Does somebody know if it is possible to achieve this?

ghost commented 3 years ago

$event->response

asiermusa commented 3 years ago

Hi @voyula!

I know that $event has different type of properties as response, but is there any way to caught the $event->response as a json response in your controller for example?

Thanks

ghost commented 3 years ago

You can put the event response to a Laravel Cache key, and you can get the event response on Laravel Cache key after notify command on controller. But i think will work on only Queue Sync mode.