Posts

Chapter 23 - How to use Firebase Social Login Authentication in Laravel Socialite Package

Image
In this chapter, we will learn how to connect Laravel Socialite package to Firebase Authentication Social Login Provider. How to enable social option in Firebase Authentication Console and insert credentials of app and handling the callback from Social Login Page.  Before we start, we assume you have all knowledge of setting up the Firebase Authentication and Laravel Socialite package integration. If not please read this   Chapter 15  for Firebase Authentication and  Laravel Socialite . From Firebase Authentication Console. To Laravel Login with Social Options The very first step to enable all three social login providers from Firebase Authentication Panel. Simply click on sign in providers which you want, for example we have clicked on Facebook. Then click on enable. Here we assume, you know all the steps of creating app in Facebook, Google, Twitter and obtain their app id and secret. Just enter app id and secret and click on save. So now your Facebook is...

Chapter 22 - How to write trigger functions in Firebase Cloud Functions

Image
In this chapter, we will learn how to create a function that basically acts a MySQL triggers.We will learn in depth how the onCreate, OnUpdate, OnWrite, OnDelete methods of Firebase Cloud Functions works. So we will understand this by an example,  whenever a Student takes a exam for subject, increase the counter of "Exams" in Student. A cloud function keeps an watch on document mentioned and whenever any action (crud) takes places, you can write your piece of action. Now consider this the basic Student structure And a basic subject structure And you insert a data in Exam collection, whenever a student takes an exam of Subject with marks obtained. Now you update "totalexams" a counter field which shows total exams taken by student and a "totalmarks" fields which is summation of marks of all Exams took by that Student. So lets write a function onCreate for the Exam/{ExamID}. Before starting this, please read the basic installation and deploying funct...

Extend your Firebase Cloud Firestore Realtime Database with Cloud Functions #21

Image
Firebase Cloud Functions are not related to Laravel PHP code. You cannot code cloud functions in Laravel. Basically they are some code hosted in Firebase Console itself (Serverless). So you have to come out of your PHP stuff and code in Javascript. You have to see this as MySQL triggers. When you create, update, delete data in Cloud Firestore, you can write certain actions. For an example, whenever a Student takes a exam for subject, increase the counter of "Exams" in Student. So we need to understand Cloud Functions for our upcoming chapters, where we learn to make Full text search using Algolia or ElasticSearch and many stuffs like that. Lets get started You can find the Functions tab in the Sidebar of Cloud Functions. It will instruct you to install firebase tool in your pc. So before running this command in local PC, make sure you have installed Nodejs version 10 (at time of this chapter written, may change...

Chapter 20 - How to fetch and delete an image from Firebase Storage using Laravel PHP project

Image
In this chapter, we will learn how to fetch an image and delete an image from the Firebase Storage using the Laravel PHP project with the kreait/laravel-firebase package. First of all we assume that you have read our previous chapter on how to upload an image to the Firebase Storage from the Laravel PHP project using the kreait/laravel-firebase package. Chapter 19 In below example, we have "Students" folder in the root of the bucket. And inside the folder, we have a png image with document id of the student. So you have the path now "Students/defT5uT7SDu9K5RFtIdl.png" Now we will fetch the images from the path. And this can be achieved by following code $expiresAt = new \DateTime('today'); $imageReference = app('firebase.storage')->getBucket()->object("Students/defT5uT7SDu9K5RFtIdl.png"); if($imageReference->exists()) $image = $imageReference->signedUrl($expiresA...

How to Upload files with Cloud Storage on Web - Firebase #19

Image
In this chapter, we will learn how to upload an image to the Firebase Storage from the Laravel PHP project using the kreait/laravel-firebase package. First of all you have to visit the Storage tab in the Firebase. And click on the "Get Started". Then on click of get started, you will find two options to setup the rules and the location. For now keep the rules as it is. By default, rules would be allowed all reads and writes from authenticated users. You can learn more for making it more secure, but its not generally required. Now the free Blaze plan does not allow the location change. It will default to us-central. After successful setup, you would land to the root folder. This is similar to any folder structure. You can create any n level folders. We have created the Student folder and will upload student images with Firebase doc id of Stude...

How to make Firebase query search not case sensitive #18

Image
How to make Firebase query search not case sensitive because you know Firebase provide exact match "==" with case sensitive. So we will solve this issue in the chapter in detail. We will use the Laravel PHP SDK for the firebase for all the queries stuff. Also we will see case insensitive sorting with Firebase orderBy using Firebase search ignoring case. Now lets consider a simple example, you have 'Student' list and you want to search by name. So the main use of any search is that, you insert one or two characters and the system should search the most matching one, but that not the case in Firebase. Firebase is a case sensitive. Means string "Name" and "name" are two different values for Firebase. All Firebase developers are facing this issue, which is most basic necessity. So lets first understand, currently what is provided by Firebase. See the below example of Student List. Now here you see, we have a Student ...

How to Query based on multiple where clauses using eq filters in Firebase #17

Image
Learn how to Query based on multiple where clauses using eq filters in Firebase to perform simple and compound queries in Cloud Firestore. In this chapter, we will learn to query based on multiple where clauses in Firebase because you know Firebase provide exact match "==" with case sensitive. So we will solve this issue in the chapter in detail. We will use the Laravel PHP SDK for the firebase for all the queries stuff. Now lets consider a simple example, you have 'Student' list and there are two fields 'firstname' and 'lastname' and you want to search in both fields at the same time. So the main use of any search is that, you insert one or two characters and the system should search the most matching one, but that not the case in Firebase. All Firebase developers are facing this issue, which is most basic necessity. So lets first understand, currently what is provided by Firebase. See the below example of Student List. Now here yo...