laravel-notification-channels / fcm

Firebase Cloud Messaging (FCM) notifications channel for Laravel
https://laravel-notification-channels.com/
MIT License
495 stars 127 forks source link

setData method not sending all the given data. #60

Closed pratamatama closed 4 years ago

pratamatama commented 4 years ago

I've implemented this package in my app, I also wrote this question on StackOverflow. Notification works, but it does not gave me all data I needed.

CreatedAgenda.php

return FcmMessage::create()
    ->setTopic('agenda')
    ->setData([
        'agenda' => $this->agenda,
        'data2' => 'hello world!',
        'click_action' => 'FLUTTER_NOTIFICATION_CLICK',
    ])
    ->setNotification($notification)
    ->setAndroid($androidConfig)
    ->setApns($iosConfig);

Debug Console (client side)

I/flutter (31507): ┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
I/flutter (31507): │ NotificationService: onMessage
I/flutter (31507): ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
I/flutter (31507): │ 🐛 {
I/flutter (31507): │ 🐛   "notification": {
I/flutter (31507): │ 🐛     "title": "Agenda Invitation",
I/flutter (31507): │ 🐛     "body": "You've been invited to participate in Wirda's agenda."
I/flutter (31507): │ 🐛   },
I/flutter (31507): │ 🐛   "data": {
I/flutter (31507): │ 🐛     "click_action": "FLUTTER_NOTIFICATION_CLICK"
I/flutter (31507): │ 🐛   }
I/flutter (31507): │ 🐛 }
I/flutter (31507): └───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
pratamatama commented 4 years ago

solved by modifying the script to this:

->setData([
    'data' => json_encode($this->agenda),
    'click_action' => 'FLUTTER_NOTIFICATION_CLICK',
])