mpociot / laravel-firebase-sync

Synchronize your Eloquent models with a Firebase Realtime Database.
http://marcelpociot.com/blog/2016-06-20-synchronise-laravel-eloquent-models-with-firebase
265 stars 71 forks source link

Data save with numeric property #3

Closed TomasNiDo closed 7 years ago

TomasNiDo commented 8 years ago

Hi, I noticed that every time I save a data, it's under a numeric property. is there any other way to modify this?

tokens
    |-- 1
        |-- id: 1
        |-- key: jOIawd987d
        |-- another_field: 'another_value'
chris-mackie commented 8 years ago

when sending the number like below if you want to save it as a string

var number = '123456789';

number = number.toString();
mikemclin commented 7 years ago

That is the way Firebase stores data. You've put an object in the tokens/1 slot. There always needs to be a unique slot for each record. So, by default the slot names are the primary keys from the Laravel models, because they are guaranteed to be unique.

If for some reason you did not want your primary key to be the Firebase identifier (which would be a non-normal use case), then you can override the saveToFirebase method in the trait and determine your own path.