Laravel Firebase

Laravel Firebase
  1. Firebase Cloud Messaging (FCM) is a cross-platform messaging solution that lets you reliably send messages at no cost.Using FCM, you can notify a client app.
  2. Sep 17, 2020 Add Firebase in Angular. Adding Firebase in Angular is easy, it can be done with a single command. However, you must create a Firebase project for making the interaction between server and client. Npm install firebase @angular/fire. AngularFire2 is a Firebase package and has been installed, now add the given below code in app.module.ts.
In this Ionic 5 Angular Firebase push notification tutorial, we will learn how to create and send push notifications from Firebase Cloud Messaging to Ionic Angular application using Ionic native and Cordova FCM plugin from scratch.

In this article, you will learn how to conditionally redirect users after login to Laravel Jetstream and Fortify applications. With the introduction of Laravel Jetstream, it is always tempting to setup Laravel projects with Laravel Jetstream and Fortify handling the authentication of your app.

A push notification is a message that shows up on a user’s mobile device. App owners can publish push notification at any time and send it to the user’s device.

Push notifications seem similar to SMS or text messages and mobile alerts. However, they only received by users who have installed your app. Almost every mobile platform supports push notifications such as iOS, Android, Fire OS, Windows, and BlackBerry.

Push notifications provide you updates, be it:

  • Latest offers to boost sales
  • Latest sports scores and news
  • Reports about traffic and weather
  • Flight check-in, change, and connection information

Table of Contents

Prerequisite

To get started with this Ionic push notification tutorial, we must have the following tools, frameworks, and packages in our arsenal.

  • Latest Node
  • Ionic
  • Angular
  • Firebase FCM
  • Postman
  • Text Editor
  • Cordova
  • Ionic Cordova Native FCM

If you do not have Node.js installed on your device then follow this tutorial on: How to Download and Install Node.js and npm

Firebase Setup for Android

To set up Firebase for Android, head over to console.firebase.google.com and create a Firebase project.

Next, a full-screen pop up appears on your screen, enter your project name in the input field and click on the continue button.

In the second screen, you will see Google analytics features you can enable them and click on the create project button.

In the dashboard, you will have options to set up Firebase account for iOS, Android, Web, and Unity. Click on the Android button, and you will be redirected to the given screen.

Next, we will add Firebase to our Android app.

To register the app add the Android package name in the input field. For instance, we entered com.positronx.pushnotification then provided the app’s nickname (same as Ionic project name); however, its an optional value. Then click on the Register app button.

Firebase

Next, you will see the following screen that allows you to Download the config file, which is used to run the mobile app in the Android Studio or emulator.

Click on the Download google-services.json file. We have to add this file to the based folder of our Ionic app.

Click on the next button unless you reach to the last screen that can be skipped.

We have successfully created the Firebase application for Android platform.

Create Ionic 5 Push Notification App

Make sure you have the latest version of Ionic CLI and Cordova installed on your machine, use below command to install Ionic CLI globally your machine:

Check out the version of Ionic by running the following command.

Run the following command to create a brand new blank Ionic 5 Firebase push notification app.

Get inside the project folder.

Run the following command in the terminal to install the lab plugin as a dev dependency.

Run the command to start the app in the browser, we can see app in iOS and Android mode.

Install & Configure Ionic Cordova Native FCM Plugin

Now, we type the below command in the terminal to Install Google Firebase Cloud Messaging Cordova Push Plugin and Ionic Native FCM plugins.

FCM offers basic functionality for Firebase Cloud Messaging (FCM) and It supports iOS and Android.

Open your Ionic project and head over to the config.xml file. Here you can see the widget id “com.positronx.pushnotification” that carries the unique identification of your push notification app, here you have to add the package name that we defined in the Firebase.

This time we will inject FCM service to enable the Push notification service in our Ionic app via Firebase FCM, go to app.module.ts file and add the following code in the main app module file.

We imported FCM plugin and register in the providers array.

Push Notification Implementation in Ionic 5

Now, we will implement push notification in our Ionic Cordova app through Firebase Cloud Messaging.

Head over to command prompt type following commands and commence installing SplashScreen and StatusBar plugins.

Place the following code in the app.component.ts file.

We imported FCM API from ‘@ionic-native/fcm/ngx’ and Router from ‘@angular/router’.

Inject FCM and Router services in the constructor.

We can access to subscribeToTopic method via FCM package and subscribe to a topic, the subscribeToTopic() takes the topic name as a parameter.

The fcm.getToken() method returns a token of a push notification, and we are showing the token in the console.

The fcm.onNotification() method returns a push notification from Firebase Cloud Messaging.

The fcm.onTokenRefresh() method allows refreshing the Firebase Cloud Messaging (FCM) token.

Use unsubscribeFromTopic() method to unsubscribe from a topic from FCM.

Sending and Receiving Push Notification in Ionic 5 via FCM

In this step, we will create the project build; let’s run the below command to add the Android platform in Ionic app.

In this step, we will add the google-services.json in the root of our project and also inside the platform/android folder file that we downloaded from Firebase FCM. This step is crucial, and it makes communication between the Ionic app and Firebase.

Run the Ionic app in the Android device by using the following command.

We used the --livereload tag. It automatically creates the build as soon as it noticed any change in the application files.

Firebase

Firebase Cloud Messaging Example

Go to your Firebase dashboard click on Grow > Cloud Messaging, we define Firebase Notification here, add the notification title, text even you can pass the notification image here.

Click on the ‘Send test message’ button, and it will open a popup where you have to define the Firebase Cloud Messaging token to send push notification to the Ionic app.

Type chrome://inspect in the address bar, then select the inspect mode there you can see the Firebase push notification token that we will need in the next step.

We have done all the formalities, and now we will hit on the Test button to send a test notification.

Conclusion

Laravel Firebase Notification

The Ionic 5 Firebase FCM Push Notification Tutorial is over; in this tutorial, we have learned how to send push notifications from Firebase and receive notification in an Ionic app.

You can get the complete code of this tutorial on this GitHub repository.

A Laravel package for the Firebase PHP Admin SDK
2021/04/24 00:21 (dev-main)
GitHub - Packagist
698 046
laravel - gcm - firebase - fcm
dev-main
2021/04/24 00:21
  • illuminate/contracts ^6.0 ^7.0 ^8.0
  • illuminate/support ^6.0 ^7.0 ^8.0
  • php ^7.2 ~8.0.0
  • kreait/firebase-php ^5.18
dev-contracts
2021/04/24 00:21
  • php ^7.2 ~8.0.0
  • illuminate/contracts ^6.0 ^7.0 ^8.0
  • illuminate/support ^6.0 ^7.0 ^8.0
  • kreait/firebase-php ^5.18
3.1.0
2021/02/02 23:32
  • php ^7.2 ~8.0.0
  • kreait/firebase-php ^5.14.1
  • illuminate/contracts ^6.0 ^7.0 ^8.0
  • illuminate/support ^6.0 ^7.0 ^8.0
3.0.0
2020/11/01 17:36
  • php ^7.2 ^8.0
  • kreait/firebase-php ^5.11.0
  • illuminate/contracts ^6.0 ^7.0 ^8.0
  • illuminate/support ^6.0 ^7.0 ^8.0
2.4.0
2020/10/04 12:17
  • php ^7.2 ^8.0
  • kreait/firebase-php ^5.8.1
  • illuminate/contracts ^5.8 ^6.0 ^7.0 ^8.0
  • illuminate/support ^5.8 ^6.0 ^7.0 ^8.0
2.3.1
2020/09/08 20:09
  • php ^7.2
  • kreait/firebase-php ^5.8.1
  • illuminate/contracts ^5.8 ^6.0 ^7.0 ^8.0
  • illuminate/support ^5.8 ^6.0 ^7.0 ^8.0
Laravel firebase auth2.3.0
2020/09/08 19:41
  • php ^7.2
  • kreait/firebase-php ^5.8.1
  • illuminate/contracts ^5.8 ^6.0 ^7.0 ^8.0
  • illuminate/support ^5.8 ^6.0 ^7.0 ^8.0
2.2.0
2020/06/20 14:28
  • php ^7.2
  • kreait/firebase-php ^5.0
  • illuminate/contracts ^5.8 ^6.0 ^7.0
  • illuminate/support ^5.8 ^6.0 ^7.0
2.1.0
2020/05/27 17:51
  • kreait/firebase-php ^5.0
  • illuminate/contracts ^5.8 ^6.0 ^7.0
  • illuminate/support ^5.8 ^6.0 ^7.0
2.0.0
2020/04/01 15:06
  • kreait/firebase-php ^5.0
  • illuminate/contracts ^5.8 ^6.0 ^7.0
  • illuminate/support ^5.8 ^6.0 ^7.0
1.5.0
2020/02/29 11:43
  • kreait/firebase-php ^4.40.1
  • illuminate/contracts ^5.8 ^6.0 ^7.0
  • illuminate/support ^5.8 ^6.0 ^7.0
1.4.0
2020/02/22 13:04
  • kreait/firebase-php ^4.40.0
  • illuminate/contracts ^5.8 ^6.0
  • illuminate/support ^5.8 ^6.0
1.3.0
2020/01/15 19:13
  • kreait/firebase-php ^4.38.1
  • illuminate/contracts ^5.8 ^6.0
  • illuminate/support ^5.8 ^6.0
1.2.0
2019/10/25 23:22
  • kreait/firebase-php ^4.35.0
  • illuminate/contracts ^5.8 ^6.0
  • illuminate/support ^5.8 ^6.0
1.1.0
2019/09/19 08:21
  • kreait/firebase-php ^4.32.0
  • illuminate/contracts ^5.8 ^6.0
  • illuminate/support ^5.8 ^6.0
1.0.1
2019/08/19 08:53
  • kreait/firebase-php ^4.30.1
  • illuminate/contracts ^5.8 ^6.0
  • illuminate/support ^5.8 ^6.0
1.0.0
2019/08/17 11:59
  • kreait/firebase-php ^4.30

Laravel Firebase

Please enable JavaScript to view the comments powered by Disqus.comments powered by Disqus

A Laravel package for the Firebase PHP Admin SDK.

  • Installation
  • Usage

Installation

This package requires Laravel 6.x and higher or Lumen 6.x and higher.

If you use Lumen or don't use Laravel's package auto-discovery, add the following service provider inconfig/app.php (Laravel) or bootstrap/app.php (Lumen):

Laravel

Lumen

Upgrade

See UPGRADE.md for upgrade instructions.

Configuration

In order to access a Firebase project and its related services using a server SDK, requests must be authenticated.For server-to-server communication this is done with a Service Account.

The package uses auto discovery for the default project to find the credentials needed for authenticating requests tothe Firebase APIs by inspecting certain environment variables and looking into Google's well known path(s).

If you don't already have generated a Service Account, you can do so by following the instructions from theofficial documentation pages at https://firebase.google.com/docs/admin/setup#initialize_the_sdk.

Once you have downloaded the Service Account JSON file, you can configure the package by specifyingenvironment variables starting with FIREBASE_ in your .env file. Usually, the following arerequired for the package to work:

Laravel Firebase Library

For further configuration, please see config/firebase.php. You can modify the configurationby copying it to your local config directory or by defining the environment variables used in the config file:

Usage

ComponentAutomatic InjectionFacadesapp()
AuthenticationKreaitFirebaseAuthFirebase::auth()app('firebase.auth')
Cloud FirestoreKreaitFirebaseFirestoreFirebase::firestore()app('firebase.firestore')
Cloud Messaging (FCM)KreaitFirebaseMessagingFirebase::messaging()app('firebase.messaging')
Dynamic LinksKreaitFirebaseDynamicLinksFirebase::dynamicLinks()app('firebase.dynamic_links')
Realtime DatabaseKreaitFirebaseDatabaseFirebase::database()app('firebase.database')
Remote ConfigKreaitFirebaseRemoteConfigFirebase::remoteConfig()app('firebase.remote_config')
Cloud StorageKreaitFirebaseStorageFirebase::storage()app('firebase.storage')
Laravel firebase

Once you have retrieved a component, please refer to the documentation of the Firebase PHP Admin SDKfor further information on how to use it.

You don't need and should not use the new Factory() pattern described in the SDK documentation, this is alreadydone for you with the Laravel Service Provider. Use Dependency Injection, the Facades or the app() helper instead

Multiple projects

Multiple projects can be configured in config/firebase.php by adding another section to the projects array.

When accessing components, the facade uses the default project. You can also explicitly use a project:

Support

Laravel Firebase Auth Tutorial

License

Firebase Admin PHP SDK is licensed under the MIT License.

Laravel Firebase Notification

Your use of Firebase is governed by the Terms of Service for Firebase Services.

Nordvpn good