How to use Firebase Realtime database in your Laravel App

LikeReal time database,Push notification,Firebase Analytics,Firebase Authentication,Firebase Cloud Messaging,Firebase Storage,Firebase Hosting,Firebase Test Lab For Android,Firebase Crash reporting,Firebase Notification, Firebase App Indexing,Firebase Dynamic link, Firebase Invites, and Firebase Adwords.but we will explain how to use firebase real-time database in your laravel app.PrerequisitesComposer (optional)Terminal or CMDText Editor (Anyone of your choice)Laravel 5.7PHP >= 7.1.3Google Firebase Realtime DatabaseWeb server (Apache, NGINX or integrated PHP web server for testing).Getting StartedThe first thing we are going to do is create a new laravel application..If you have the Laravel installer, you can run the following command:$ laravel new laravel-firebaseIf you do not have the Laravel installer, you can get it by running the following command:$ composer global require "laravel/installer"Or you can start a new laravel application via composerDownload composer from here and install it, then run the command below in your terminal$ composer create-project –prefer-dist laravel/laravel laravel-firebaseOpen the directory of the laravel project in your terminal by running$ cd laravel-firebaseThen you install Kreait Firebase Package$ composer require kreait/firebase-php ^4.0With the above completed we need to set up a Firebase Account.Setting Up FirebaseLet’s start with signing in our Gmail account..In the next tab, open the Firebase page, click on Visit Console.Next, in the next window, create a database project and provide information including project name..When done, click the Create Project button.Wait for the project to be created and then continue..You will be automatically redirected to the Firebase Dashboard.After successfully creating the project, go to the Database tab, scroll down you will Or choose Realtime Database, click create database.Choose Start in test modeGenerate the API KeyClick on the settings icon, then click on Project SettingsClick the Service Account tab and click on Generate new private key tab.The key will be created in JSON format and downloaded automatically..You can copy the file to the http/controller folder of Laravel.Create the ControllerAfter pasting the API Key in the Controller folder, go to the in Terminal and type the following command to create the Controller:$ php artisan make:controller FirebaseControllerNext, paste the following code in the Controller file:Remember to replace the file path in fromJsonFile with your own file path..Also, replace the database URL with your database’s URL:Set up the RouteOpen the Laravel routes/web.php file with your text code and update the following code:Save all changes in the Laravel application and run your application by running the below command in your terminal :$ php artisan serveOpen your browser and run the generated link which should be http://localhost:8000, You should be having this after running it on your browser.Firebase DatabaseConclusionI hope that by now you have a very good idea of using Firebase Realtime Database in Laravel project.. More details

Leave a Reply