Posts

Showing posts with the label Cloud Firestore

Chapter 12 - Delete data from Firebase using Laravel PHP

Image
In this chapter, we will learn how to delete the data from Firebase Cloud Firestore database collection using Laravel Framework PHP SDK. Now consider the following list of students in the 'Student' collection Suppose you want to delete the Student by document id '8suVf4FphzZLuTFJtdFe', you have to fire the below query. app('firebase.firestore')->database()->collection('Student')->document('8suVf4FphzZLuTFJtdFe')->delete(); This will delete the Student data from Student collection. Now if you have to delete the student having id = 3, then this can be done by the following query $students = app('firebase.firestore')->database()->collection('Student')->where('id','==',3)->limit(1)->documents(); $students ->rows()[0]->delete(); Now consider if you have to delete students having 'passoutyear' ...

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')...

Chapter 5 - Integrate Laravel with Google Firebase connecting Cloud Firestore

Image
In this chapter, we will create a Laravel project and connect it with the Cloud Firestore with installing all necessary packages and build some basic queries. Step 1: Install a fresh Laravel Project with name my-project composer create-project --prefer-dist laravel/laravel my-project Step 2: Setup a Firebase account and Cloud Firestore Database A detail chapter on this topic is available here  https://laravelwithfirebase.blogspot.com/2020/02/chapter-3-creating-project-in-firebase-for-laravel-php.html Step 3: Use the Laravel package built over Firebase PHP Admin SDK by Kreait The package url on Github: https://github.com/kreait/laravel-firebase. We have already explain the Firebase PHP Admin SDK in previous chapters by the same Author. So this code has been used by lot of people and is highly maintainable. Run the following command to install the package. composer require kreait/laravel-firebase ...

How to add Laravel package for the Firebase PHP Admin SDK #4

Image
Learn how to add firebase admin sdk to laravel project - php. In this chapter, we will introduce you to SDK built by Kreait ( https://github.com/kreait ). Note this is not official SDK by Firebase. But the most used (1.4M downloads and 1.1K Stars) and maintainable code. Note we are going to use the Laravel - Firebase package built on above it  https://github.com/kreait/laravel-firebase  and Google Firestore PHP SDK   https://github.com/googleapis/google-cloud-php-firestore . So if you want to start building Laravel app, you can jump to related chapter but understanding base code is always necessary. So lets begin. The official document url is https://firebase-php.readthedocs.io/ and github url is  https://github.com/kreait/firebase-php . The minimum requirement of PHP for this package >= 7.0 mbstring, composer and the firebase json credential file explained in before chapters. Installation can be done in your PHP project through composer comp...

Chapter 1 - Introduction to Firebase

Image
In this chapter we are going to achieve basic knowledge of the Firebase, with it different types and how it can replace SQL database. Firebase is a NoSQL document database that lets you easily store, sync, and query data for your mobile and web apps - at global scale. Structure your data easily with collections and documents. Build hierarchies to store related data and easily retrieve the data you need using expressive queries. All queries scale with the size of your result set (note: not your data set), so your app is ready to scale from day one. MySQL  >  Databases  > Tables >  Columns/Rows Cloud Firestore  > Collections  >  Documents > ... Now, above return is Cloud Firestore. Not to confuse here. It is one of type of Firebase. Firebase has two types of database, one is Realtime Database and another one is Cloud Firestore. Now again don't be confused with the name Realtime i.e this is the realtime database. Both are s...