Cloud Firestore

This SDK provides a bridge to the google/cloud-firestore package. You can enable the component in the SDK by adding the package to your project dependencies:

composer require google/cloud-firestore

Note

The google/cloud-firestore package requires the gRPC PHP extension to be installed. You can find installation instructions for gRPC at github.com/grpc/grpc. The following projects aim to provide support for Firestore without the need to install the gRPC PHP extension, but have to be set up separately:

Before you start, please read about Firestore in the official documentation:

Initializing the Firestore component

With the SDK

$firestore = $factory->createFirestore();

With Dependency Injection (Symfony Bundle/Laravel/Lumen Package)

use Kreait\Firebase\Contract\Firestore;

class MyService
{
    public function __construct(Firestore $firestore)
    {
        $this->firestore = $firestore;
    }
}

With the Laravel app() helper (Laravel/Lumen Package)

$firestore = app('firebase.firestore');

Getting started

$database = $firestore->database();

$database is an instance of Google\Cloud\Firestore\FirestoreClient. Please refer to the links above for guidance on how to proceed from here.

Use another Firestore Database

If you don’t specify a database, the Firestore Client will connect to the (default) database.

If you want to connect to another database, you can specify its name when creating a new instance. This enables you to work with multiple Firestore Databases simultaneously.

use Kreait\Firebase\Factory;

$factory = new Factory();

$default = $factory->createFirestore();
$explicitDefault = $factory->createFirestore('(default)');
$custom = $factory->createFirestore('custom');

Add Firestore configuration options

You can add additional configuration options for the Firestore Client used by the Firestore component:

use Kreait\Firebase\Factory;

$factory = new Factory();

$firestore = $factory
    ->withFirestoreClientConfig([...])
    ->createFirestore();

You can find all configuration options in the source code of the FirestoreClient class of the official Google Firestore PHP library.