• 14
Votes

how can i perform crud operation in cloud firestore in php

to connect with database 

use GoogleCloudFirestoreFirestoreClient;
$projectId = "dshds-221";
$keyFilePath = dsdsds-w2";
$db = new FirestoreClient([
'projectId' => $projectId,
'keyFilePath' => $keyFilePath
]);

now you can execute all examples listed here 

user more examples here

https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/firestore/src

  • 0
Reply Report

go to https://github.com/morrislaptop/firestore-php install this using composer but it does not contain lot of examples to work with cloud firestore in php.

<?php 
use MorrislaptopFirestoreFactory;
use KreaitFirebaseServiceAccount;

require 'vendor/autoload.php';

// This assumes that you have placed the Firebase credentials in the same directory
// as this PHP file.
$serviceAccount = ServiceAccount::fromJsonFile('demo-ea17431dsdsda.json');

//get above json  file from here https://console.cloud.google.com/apis/credentials

$firestore = (new Factory)
    ->withServiceAccount($serviceAccount)
    ->createFirestore();

$collection = $firestore->collection('users');
$user = $collection->document('1234567');

// Save a document
$user->set(['name' => 'morrislaptop', 'role' => 'developer','address' => 'developer']);

// Get a document
$snap = $user->snapshot();
echo $snap['name']; // morrislaptop

?>

 

user more examples here

https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/firestore/src

  • 1
Reply Report