plokko / firebase-php

Php integration of Firebase API (FCM Http v1, RealTime database)
16 stars 9 forks source link

Can not submit data as nested array #19

Closed Nagasir closed 4 months ago

Nagasir commented 5 months ago

Hello,

Thank you for your awesome code, but I have a problem sending this kind of nested array in the data property

$message->data->fill(
      [
     “type_of_food” => ”vegetable”,
     “example” => 
                [
                    0 => 
                      [
                          "red" => “carrots”,
                          "green" => “broccoli”
                      ]
           ]
      ]
)

Could you please help..the "example" part still recognized as an array in Flutter code

plokko commented 4 months ago

This is a PHP bug in your code: PHP arrays could be converted as an array or an object so if you want the "example" to be rendered as an object cast it like so:

$message->data->fill(
      [
     “type_of_food” => ”vegetable”,
     “example” => 
                (object)[
                    0 => 
                      [
                          "red" => “carrots”,
                          "green" => “broccoli”
                      ]
           ]
      ]
)