php - Firebase database find key
Solution:
You'll want to change this code:
$newUser = $database
->getReference('user')
->push($user);
When you call push()
, Firebase creates a unique ID for the new data. What you want instead is to store the new data under a key you control, the UID of the user. That'd look something like this:
$newUser = $database
->getReference('user')
->getChild("the uid of the user")
->set($user);
For getChild("the uid of the user")
you'll then have to use the UID of the user, which unfortunately I can't see where to get it from in your code.
Answer
Solution:
SOLVED
Thanks to Frank van Puffelen
answer it was great lead to me, here is how I solved this issue.
$user->save();
// now that my DB is updated, start to update firebase
$factory = new Factory;
$firebase = $factory
->withServiceAccount(base_path(env('FIREBASE_CREDENTIALS')))
->withDatabaseUri('https://myapp-d54e6.firebaseio.com/');
$database = $firebase->createDatabase();
$getData = $database->getReference('users')->getvalue();
foreach($getData as $key_user => $userr) {
// In case of using variables outside of this loop
//if(in_array($id, $userr)) {
//$final_user = $userr;
//$fireKey = $key_user;
//}
$newUser = $database
->getReference('users')
->getChild($key_user)
->set($user);
}
Source