Posts

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

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

How to perform sql LIKE operation on Firebase in Laravel PHP #16

Image
How to perform the like queries on 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 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. 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 named 'Tim Dane'. Now you have to search this student from whole list, so you start time 'Tim', so atleast it should be match one matching word. So do Firebase return has "Tim Dane" on search of "...

Chapter 15 - Laravel with Firebase Sign In and maintain logged in session using middleware

Image
In this chapter, we will learn how can we implement a login page and make a user login. Then maintain a session for other page queries and logout to destroy session. Before we start, we assume you have all knowledge of setting up the Firebase Authentication. If not please read this  Chapter 6 First of all, below is the code of login method with takes email and password and checks if the credentials is correct or incorrect. try { $logged_user = app('firebase.auth')->verifyPassword($request->emailaddress, $request->password); //Credentials are correct } catch (\Kreait\Firebase\Exception\Auth\InvalidPassword $ex) { return back()->withErrors(['Credentials are incorrect']); } Now if Credentials are correct, then store the uid in the Laravel Session \Session::put('uid', $logged_user->uid); Now create a custom middleware. lets us name it as 'firebase...

How to use firebase reset password custom and manage & reset forgotten users passwords - #14

Image
Learn how to use custom firebase reset password and manage & reset forgotten users passwords. Detailed how to implement the custom Firebase Auth Forgot/Reset Password template and send to user on Forgot Password Request. And the reset password URL would contain URL to your site instead of Firebase default URL. And on visit of this URL, how to call verify method of Firebase Auth and Form containing password fields submission in Laravel PHP with little help of JavaScript SDK. Here, before we start, please read this Email verification chapter  https://laravelwithfirebase.blogspot.com/2020/04/chapter-13-implement-custom-firebase-auth-email-verification-template-replace-default-view-using-laravel-php.html Most of below content would be same. Now lets begin to customize the URL, you get in your firebase email verification template. It looks like something  https://test-cc4d3.firebaseapp.com/__/auth/action?mode=<action>&oob...

How to create custom firebase email templates and action handlers link #13

Image
Learn how to create custom email action handlers and change the Firebase email templates using Firebase email link authentication. Detailed how to implement the custom Firebase Auth Email verification template and send to user on signup. And the verification URL would contain URL to your site instead of Firebase default URL. And on visit of this URL, how to call verify method of Firebase Auth in Laravel PHP with little help of JavaScript SDK. Here, we assume, your are clear about Firebase Auth and you have enabled the Email/Password in the Sign-in method Now lets begin to customize the URL, you get in your firebase email verification template. It looks like something  https://test-cc4d3.firebaseapp.com/__/auth/action?mode=<action>&oobCode=<code> Here, in above image, you have edit button for the editing the template. Click on that, then you will have "customize action URL" link at the bottom...

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