kawankoding / laravel-fcm

Firebase Cloud Messaging (FCM) sender for Laravel
172 stars 56 forks source link

Note added in readme about sending different payloads #38

Closed bjrnblm closed 4 years ago

bjrnblm commented 4 years ago

I am using this package to send different payloads to Android devices and iOS devices in one request. This gave me some problems, because this package reuses theFcm class via a singleton.

iOS:

fcm()->to($recipients)
  ->notification([
    'title' => 'title',
  ])
  ->data([
    'title' => 'title',
  ])
  ->send()

Android:

fcm()->to($recipients)
  ->data([
    'title' => 'title',
  ])
  ->send();

If i send an iOS notification first the Fcm class has a $notification property which gives problems inside the Android app. However I am not able to reset / remove this property from the Fcm class anymore.

Failed solutions: An empty array in the notification method gives a null response from Firebase:

fcm()->to($recipients)
  ->notification([])
  ->data([
    'title' => 'title',
  ])
  ->send();

A null in notification method is not possible because of typehinting in the current package

fcm()->to($recipients)
  ->notification(null)
  ->data([
    'title' => 'title',
  ])
  ->send();

Note in docs: That is why I added a note to the docs with a workaround by using the Fcm class directly instead the the facade or helper.

Would be nice to in the future to be able to reset class properties in the Fcm class by updating them with null. I could make PR for that too if you are interested.

erlangparasu commented 4 years ago

Thanks @bjrnblm

erlangparasu commented 4 years ago

@bjrnblm singleton problem has fixed by this commit: https://github.com/kawankoding/laravel-fcm/commit/07f901ce28794aca0c8386ed6532043c7b0ca2f8 lib version v0.2.0 https://github.com/kawankoding/laravel-fcm/releases/tag/0.2.0 :D