syailendra / laravel-firestore
There is no license information available for the latest version (v1.0.0) of this package.
Package for Laravel and Firestore
v1.0.0
2021-09-05 16:21 UTC
Requires
- google/cloud-firestore: ^1.19
- kreait/laravel-firebase: ^3.1
This package is auto-updated.
Last update: 2025-03-06 23:39:25 UTC
README
This package extended from kreait/laravel-firebase focusing at firestore integration and support query builder like Laravel with several limitations.
Installation
This package requires :
- Laravel 6.x and higher
- gRPC extension
Composer
composer require syailendra/laravel-firestore
Service Provider
<?php // config/app.php return [ // ... 'providers' => [ // ... Syailendra\Firebase\LaravelFirestoreServiceProvider::class, ] // ... ];
Usage
Read Data
Get Documents from Collection
$getDocs = Firestore::collection('collection_name') ->get();
Get a Document from Collection
$data = Firestore::collection('collection_name') ->whereDoc("document_id")->snapshot();
Get sub Collection
$data = Firestore::collection('collection_name') ->whereDoc("document_id")->getCollections ();
Where
$getDocs = Firestore::collection('collection_name') ->where('lastname', 'Doe') ->get();
Or with 3 parameters
$getDocs = Firestore::collection('collection_name') ->where('age', '>=', 19) ->where('lastname', '=', 'Doe') ->get();
Note : when you use two or more fields you must declare the index at firebase console.
Or with array
$getDocs = Firestore::collection('collection_name') ->where([ ['age', '>=', 19], ['lastname', 'Doe'] ]) ->get();
Order By
$getDocs = Firestore::collection('collection_name') ->orderBy('lastname') ->get();
With 2 parameters
$getDocs = Firestore::collection('collection_name') ->orderBy('lastname', 'desc') ->orderBy('age') ->get();
Note : when you use two or more fields you must declare the index at firebase console.
Or with array
$getDocs = Firestore::collection('collection_name') ->orderBy([ ["lastname", "desc"], ["age"] ]) ->get();
Limit
$getDocs = Firestore::collection('collection_name') ->orderBy('lastname') ->limit(3) ->get();
Insert Data
$insert = Firestore::collection('collection_name') ->insert([ 'firstname' => 'John', 'lastname' => 'Doe', 'age' => 19 ]);
Note : always use auto generate id.
Update Data
$update = Firestore::collection('collection_name') ->whereDoc('document_id') ->update([ 'firstname' => 'Jeremy', 'lastname' => 'Smith', 'age' => 19 ]);
Delete Data
Delete Document
$delete = Firestore::collection('collection_name') ->whereDoc("document_id") ->deleteDoc();
Delete Field
$delete = Firestore::collection('collection_name') ->whereDoc("document_id") ->deleteFields("age");
With array
$delete = Firestore::collection('collection_name') ->whereDoc("document_id") ->deleteFields(["age","lastname"]);