kreait / laravel-firebase

A Laravel package for the Firebase PHP Admin SDK
https://github.com/kreait/firebase-php
MIT License
994 stars 163 forks source link

Incompatibility with Eloquent Resources? #198

Closed mgralikowski closed 8 months ago

mgralikowski commented 9 months ago

Describe the bug

Hello,

In our previous FCM integration, we utilized Laravel Resources within the FCM data. Is this still supported? I'm asking because we're encountering errors like: Object of class App\Http\Resources\User could not be converted to a string.

My understanding is that this library converts all data to a string. Is this the intended behavior? This could also result in errors when passing a raw array (nested array).

Installed packages

Laravel 10

PHP version and extensions

PHP 8.1

Steps to reproduce the issue.

$notificationData = ['nested' => ['array']];

CloudMessage::new()
  ->withNotification(Notification::create($notificationData['title'], $notificationData['message'], $notificationData['image']))
  ->withData($notificationData);

Error message/Stack trace

-

Additional information

No response

jeromegamez commented 9 months ago

Message data can only be string keys and string values, as documented in the Firebase REST API docs at https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages#resource:-message, so, nested data is not possible.

So this is the intended behavior, but if you can make a PR changing the code to accept nested data and a test that shows that it's working, or if you can point me to where this is done in one of the official Admin SDK, I will, of course, look into it.

Could it be that your previous implementation serialized the models to a string and unserialized it on the target device?