PHPackages                             trippldee/firestore-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. trippldee/firestore-php

ActiveLibrary[Database &amp; ORM](/categories/database)

trippldee/firestore-php
=======================

Firestore PHP Client

01PHP

Since Mar 6Pushed 2y agoCompare

[ Source](https://github.com/trippldee/firestore-php)[ Packagist](https://packagist.org/packages/trippldee/firestore-php)[ RSS](/packages/trippldee-firestore-php/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)DependenciesVersions (1)Used By (0)

Firestore Client for PHP
========================

[](#firestore-client-for-php)

[![Latest Version on Packagist](https://camo.githubusercontent.com/95eb565d768a61c656077fbe311420b093e2964760555baef32c4be923eb3a12/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f616873616e6b68617472692f6669726573746f72652d7068702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ahsankhatri/firestore-php)[![Total Downloads](https://camo.githubusercontent.com/5cb6b6f0aac15ec191586397fb8b748944abd8d41195f499eaa836030b4477e2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f616873616e6b68617472692f6669726573746f72652d7068702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ahsankhatri/firestore-php)[![License](https://camo.githubusercontent.com/146fb34135dd938388e591f44ea40a6e5636da48206a914827cda2ab21129362/68747470733a2f2f706f7365722e707567782e6f72672f616873616e6b68617472692f6669726573746f72652d7068702f6c6963656e73653f666f726d61743d666c61742d737175617265)](https://packagist.org/packages/ahsankhatri/firestore-php)

This package is totally based on [Firestore REST API](https://firebase.google.com/docs/firestore/use-rest-api)

Authentication / Generate API Key
---------------------------------

[](#authentication--generate-api-key)

1. Visit [Google Cloud Firestore API](https://console.cloud.google.com/projectselector/apis/api/firestore.googleapis.com/overview)
2. Select your desired project.
3. Select `Credentials` from left menu and select `API Key` from Server key or `Create your own credentials`

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require ahsankhatri/firestore-php
```

or install it by adding it to `composer.json` then run `composer update`

```
"require": {
    "ahsankhatri/firestore-php": "^2.0",
}
```

Dependencies
------------

[](#dependencies)

The bindings require the following extensions in order to work properly:

- [`curl`](https://secure.php.net/manual/en/book.curl.php)
- [`json`](https://secure.php.net/manual/en/book.json.php)
- [`guzzlehttp/guzzle`](https://packagist.org/packages/guzzlehttp/guzzle)

If you use Composer, these dependencies should be handled automatically. If you install manually, you'll want to make sure that these extensions are available.

Usage
-----

[](#usage)

#### Initialization

[](#initialization)

```
$firestoreClient = new FirestoreClient('project-id', 'AIzaxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', [
    'database' => '(default)',
]);
```

#### Adding a document

[](#adding-a-document)

```
$firestoreClient->addDocument($collection, [
    'booleanTrue' => true,
    'booleanFalse' => false,
    'null' => null,
    'string' => 'abc123',
    'integer' => 123456,
    'arrayRaw' => [
        'string' => 'abc123',
    ],
    'bytes' => new FirestoreBytes('bytesdata'),
    'array' => new FirestoreArray([
        'string' => 'abc123',
    ]),
    'reference' => new FirestoreReference('/users/23'),
    'object' => new FirestoreObject(['nested1' => new FirestoreObject(['nested2' => new FirestoreObject(['nested3' => 'test'])])]),
    'timestamp' => new FirestoreTimestamp,
    'geopoint' => new FirestoreGeoPoint(1,1),
]);
```

**NOTE:** Pass third argument if you want your custom **document id** to set else auto-id will generate it for you.

Or

```
$document = new FirestoreDocument;
$document->setObject('sdf', new FirestoreObject(['nested1' => new FirestoreObject(['nested2' => new FirestoreObject(['nested3' => 'test'])])]));
$document->setBoolean('booleanTrue', true);
$document->setBoolean('booleanFalse', false);
$document->setNull('null', null);
$document->setString('string', 'abc123');
$document->setInteger('integer', 123456);
$document->setArray('arrayRaw', ['string'=>'abc123']);
$document->setBytes('bytes', new FirestoreBytes('bytesdata'));
$document->setArray('arrayObject', new FirestoreArray(['string' => 'abc123']));
$document->setTimestamp('timestamp', new FirestoreTimestamp);
$document->setGeoPoint('geopoint', new FirestoreGeoPoint(1.11,1.11));

$firestoreClient->addDocument($collection, $document, 'customDocumentId');
```

And..

```
$document->fillValues([
    'string' => 'abc123',
    'boolean' => true,
]);
```

#### Inserting/Updating a document

[](#insertingupdating-a-document)

- Update (Merge) or Insert document

Following will merge document (if exist) else insert the data.

```
$firestoreClient->updateDocument($documentRoot, [
    'newFieldToAdd' => new FirestoreTimestamp(new DateTime('2018-04-20 15:00:00')),
    'existingFieldToRemove' => new FirestoreDeleteAttribute
]);
```

**NOTE:** Passing 3rd argument as a boolean *true* will force check that document must exist and vice-versa in order to perform update operation.

For example: If you want to update document only if exist else `MrShan0\PHPFirestore\Exceptions\Client\NotFound` (Exception) will be thrown.

```
$firestoreClient->updateDocument($documentPath, [
    'newFieldToAdd' => new FirestoreTimestamp(new DateTime('2018-04-20 15:00:00')),
    'existingFieldToRemove' => new FirestoreDeleteAttribute
], true);
```

- Overwirte or Insert document

```
$firestoreClient->setDocument($collection, $documentId, [
    'newFieldToAdd' => new FirestoreTimestamp(new DateTime('2018-04-20 15:00:00')),
    'existingFieldToRemove' => new FirestoreDeleteAttribute
], [
    'exists' => true, // Indicate document must exist
]);
```

#### Deleting a document

[](#deleting-a-document)

```
$collection = 'collection/document/innerCollection';
$firestoreClient->deleteDocument($collection, $documentId);
```

#### List documents with pagination (or custom parameters)

[](#list-documents-with-pagination-or-custom-parameters)

```
$collections = $firestoreClient->listDocuments('users', [
    'pageSize' => 1,
    'pageToken' => 'nextpagetoken'
]);
```

**Note:** You can pass custom parameters as supported by [firestore list document](https://firebase.google.com/docs/firestore/reference/rest/v1/projects.databases.documents/list#query-parameters)

#### Get field from document

[](#get-field-from-document)

```
$document->get('bytes')->parseValue(); // will return bytes decoded value.

// Catch field that doesn't exist in document
try {
    $document->get('allowed_notification');
} catch (\MrShan0\PHPFirestore\Exceptions\Client\FieldNotFound $e) {
    // Set default value
}
```

### Firebase Authentication

[](#firebase-authentication)

#### Sign in with Email and Password.

[](#sign-in-with-email-and-password)

```
$firestoreClient
    ->authenticator()
    ->signInEmailPassword('testuser@example.com', 'abc123');
```

#### Sign in Anonymously.

[](#sign-in-anonymously)

```
$firestoreClient
    ->authenticator()
    ->signInAnonymously();
```

### Retrieve Auth Token

[](#retrieve-auth-token)

```
$authToken = $firestoreClient->authenticator()->getAuthToken();
```

### TODO

[](#todo)

- Added delete attribute support.
- Add Support for Object, Boolean, Null, String, Integer, Array, Timestamp, GeoPoint, Bytes
- Add Exception Handling.
- List all documents.
- List all collections.
- Filters and pagination support.
- Structured Query support.
- Transaction support.
- Indexes support.
- Entire collection delete support.

### Testing

[](#testing)

```
composer test
```

### Changelog

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

### Security

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Ahsaan Muhammad Yousuf](https://ahsaan.me)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

13

—

LowBetter than 1% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity1

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity19

Early-stage or recently created project

 Bus Factor3

3 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/8d54f2f32611ea27f02e96d0c0eaab426b456d130ea7d2752cf71113d184f2d2?d=identicon)[trippldee](/maintainers/trippldee)

---

Top Contributors

[![ahsankhatri](https://avatars.githubusercontent.com/u/7288116?v=4)](https://github.com/ahsankhatri "ahsankhatri (4 commits)")[![eyasthaha](https://avatars.githubusercontent.com/u/66328269?v=4)](https://github.com/eyasthaha "eyasthaha (2 commits)")[![edruid](https://avatars.githubusercontent.com/u/384380?v=4)](https://github.com/edruid "edruid (2 commits)")[![p-blomberg](https://avatars.githubusercontent.com/u/332457?v=4)](https://github.com/p-blomberg "p-blomberg (2 commits)")[![Baha2Odeh](https://avatars.githubusercontent.com/u/2823958?v=4)](https://github.com/Baha2Odeh "Baha2Odeh (1 commits)")[![mowcixo](https://avatars.githubusercontent.com/u/47653?v=4)](https://github.com/mowcixo "mowcixo (1 commits)")[![cristirusu](https://avatars.githubusercontent.com/u/1969488?v=4)](https://github.com/cristirusu "cristirusu (1 commits)")[![trippldee](https://avatars.githubusercontent.com/u/132894916?v=4)](https://github.com/trippldee "trippldee (1 commits)")

### Embed Badge

![Health badge](/badges/trippldee-firestore-php/health.svg)

```
[![Health](https://phpackages.com/badges/trippldee-firestore-php/health.svg)](https://phpackages.com/packages/trippldee-firestore-php)
```

###  Alternatives

[doctrine/orm

Object-Relational-Mapper for PHP

10.2k285.3M6.2k](/packages/doctrine-orm)[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k115.1M102](/packages/jdorn-sql-formatter)[illuminate/database

The Illuminate Database package.

2.8k52.4M9.4k](/packages/illuminate-database)[mongodb/mongodb

MongoDB driver library

1.6k64.0M546](/packages/mongodb-mongodb)[ramsey/uuid-doctrine

Use ramsey/uuid as a Doctrine field type.

90340.3M211](/packages/ramsey-uuid-doctrine)[reliese/laravel

Reliese Components for Laravel Framework code generation.

1.7k3.4M16](/packages/reliese-laravel)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
