Skip to content

Commit 4831cd1

Browse files
jeromegamezsaiht
andcommitted
Allow overriding the Firestore default database
Co-authored-by: Saiht <[email protected]>
1 parent f632f07 commit 4831cd1

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
## Unreleased
44

5+
* Added support for overriding the name of the Firestore Default Database
6+
([#209](https://github.com/kreait/laravel-firebase/pull/209))
7+
58
## 5.5.0 - 2023-11-30
69

710
* Added support for PHP 8.3

config/firebase.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,26 @@
6262
'tenant_id' => env('FIREBASE_AUTH_TENANT_ID'),
6363
],
6464

65+
/*
66+
* ------------------------------------------------------------------------
67+
* Firestore Component
68+
* ------------------------------------------------------------------------
69+
*/
70+
71+
'firestore' => [
72+
73+
/*
74+
* If you want to access a Firestore database other than the default database,
75+
* enter its name here.
76+
*
77+
* By default, the Firestore client will connect to the `(default)` database.
78+
*
79+
* https://firebase.google.com/docs/firestore/manage-databases
80+
*/
81+
82+
// 'database' => env('FIREBASE_FIRESTORE_DATABASE'),
83+
],
84+
6585
/*
6686
* ------------------------------------------------------------------------
6787
* Firebase Realtime Database

src/FirebaseProjectManager.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ protected function configure(string $name): FirebaseProject
8484
$factory = $factory->withDatabaseAuthVariableOverride($authVariableOverride);
8585
}
8686

87+
if ($firestoreDatabase = $config['firestore']['database'] ?? null) {
88+
$factory = $factory->withFirestoreDatabase($firestoreDatabase);
89+
}
90+
8791
if ($defaultStorageBucket = $config['storage']['default_bucket'] ?? null) {
8892
$factory = $factory->withDefaultStorageBucket($defaultStorageBucket);
8993
}

tests/FirebaseProjectManagerTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,20 @@ public function it_uses_the_laravel_cache_as_verifier_cache(): void
276276
$this->assertInstanceOf(CacheItemPoolInterface::class, $property->getValue($factory));
277277
}
278278

279+
/**
280+
* @test
281+
*/
282+
public function it_overrides_the_default_firestore_database(): void
283+
{
284+
config(['firebase.projects.app.firestore.database' => 'override-database']);
285+
$projectName = $this->app->config->get('firebase.default');
286+
$factory = $this->factoryForProject($projectName);
287+
288+
$property = $this->getAccessibleProperty($factory, 'firestoreClientConfig');
289+
290+
$this->assertEquals('override-database', $property->getValue($factory)['database']);
291+
}
292+
279293
/**
280294
* @test
281295
*/

0 commit comments

Comments
 (0)