diff --git a/CHANGELOG.md b/CHANGELOG.md index 6d5f58d..5c7bd03 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## Unreleased +* Added support for overriding the name of the Firestore Default Database + ([#209](https://github.com/kreait/laravel-firebase/pull/209)) + ## 5.5.0 - 2023-11-30 * Added support for PHP 8.3 diff --git a/config/firebase.php b/config/firebase.php index fe567e6..12310de 100644 --- a/config/firebase.php +++ b/config/firebase.php @@ -62,6 +62,26 @@ 'tenant_id' => env('FIREBASE_AUTH_TENANT_ID'), ], + /* + * ------------------------------------------------------------------------ + * Firestore Component + * ------------------------------------------------------------------------ + */ + + 'firestore' => [ + + /* + * If you want to access a Firestore database other than the default database, + * enter its name here. + * + * By default, the Firestore client will connect to the `(default)` database. + * + * https://firebase.google.com/docs/firestore/manage-databases + */ + + // 'database' => env('FIREBASE_FIRESTORE_DATABASE'), + ], + /* * ------------------------------------------------------------------------ * Firebase Realtime Database diff --git a/src/FirebaseProjectManager.php b/src/FirebaseProjectManager.php index 825f3d5..1b32cf8 100644 --- a/src/FirebaseProjectManager.php +++ b/src/FirebaseProjectManager.php @@ -84,6 +84,10 @@ protected function configure(string $name): FirebaseProject $factory = $factory->withDatabaseAuthVariableOverride($authVariableOverride); } + if ($firestoreDatabase = $config['firestore']['database'] ?? null) { + $factory = $factory->withFirestoreDatabase($firestoreDatabase); + } + if ($defaultStorageBucket = $config['storage']['default_bucket'] ?? null) { $factory = $factory->withDefaultStorageBucket($defaultStorageBucket); } diff --git a/tests/FirebaseProjectManagerTest.php b/tests/FirebaseProjectManagerTest.php index f3e642b..89a9472 100644 --- a/tests/FirebaseProjectManagerTest.php +++ b/tests/FirebaseProjectManagerTest.php @@ -276,6 +276,20 @@ public function it_uses_the_laravel_cache_as_verifier_cache(): void $this->assertInstanceOf(CacheItemPoolInterface::class, $property->getValue($factory)); } + /** + * @test + */ + public function it_overrides_the_default_firestore_database(): void + { + config(['firebase.projects.app.firestore.database' => 'override-database']); + $projectName = $this->app->config->get('firebase.default'); + $factory = $this->factoryForProject($projectName); + + $property = $this->getAccessibleProperty($factory, 'firestoreClientConfig'); + + $this->assertEquals('override-database', $property->getValue($factory)['database']); + } + /** * @test */