Posts

Showing posts with the label Adding data

How to auto increment a Cloud Firestore document existing number field id #9

Image
Learn How to auto increment a Cloud Firestore document existing number field id. In this chapter, we will learn how to insert a data with an auto increment id and using it an unique id instead of default Push ID provided by Firebase. Consider the following example: You have a Student collection and it has data with auto incremented value. When you insert the next, it should have id = 4. Now Firebase doesnot provide anything related to this autoincrement feature. It has only unique id generated by its logic. So we will do some manual coding for it. Now, you have the easy solution is to get the total size of the list of documents +1. Consider the following code $newid = app('firebase.firestore')->database()->collection('Student') ->documents()->size()+$i; //Insert new record app('firebase.firestore')->database()->collection('Student') ->document($ne...

Chapter 8 - Add data to Firebase using Laravel PHP

Image
In this chapter, we will learn how to insert data in Firebase Cloud Firestore from Laravel Firebase SDK demonstrating usage of various data types. Insert a simple student data in Student collection $stuRef = app('firebase.firestore')->database()->collection('Student')->newDocument(); $stuRef->set([ 'firstname' => 'John', 'lastname' => 'Doe', 'age' => 30 ]); Here firebase autoconsider the data type i.e firstname is string, lastname is string and age is number. Following are the example of sending different datatypes $docRef->set([ 'stringExample' => 'Hello World', 'booleanExample' => true, 'numberExample' => 3.14159265, 'timestampExample' => new \Google\Cloud\Core\Timestamp(new \DateTime(date('Y-m-d H:i:s', strtotime('2020-03-03 23:12:55')...