Laravel 8 Push Notification using Firebase[2]
- 2021年6月25日
- 技術情報
Here is final part how to do push notification using Firebase.Let’s start it.
Get Firebase Cloud Messaging (FCM) Server Key
This step will show how to get FCM key and Firebase web app’s configuration credentials.
Then firstly go to the Firebase site and we need to create a project.

Then add your notification app name for adding Firebase to web app.

Then copy the Firebase configuration keys, and this will help to connect laravel to Firebase.

Next, go to the project dashboard setting and copy the sever key and paste in HomeController of SERVER_API_KEY variable in sendNotification() function. Next step create the controller and let’s add the key.

Create Route
We need to do some of routes to store token and send push notification so let’s add our routes in web.php.
routes/web.php

Create Controller
Here, we need add saveToken() and sendNotification() method for admin route in HomeController.
app/Http/Controllers/HomeController.php


Then update the home.blade.php



In the final step, we have to create head over to a public folder and create a new firebase-messaging-sw.js file; this file holds the web push notification configurations.
public/firebase-messaging-sw.js

Finally, to see the push notification results we need to execute php artisan serve command. Next we will do register, signed-in and then click on the allow notification button, it will generate the device id, also add push notification title and body in the given form.
we will receive notification as like bellow:

By Ami
asahi at 2021年06月25日 10:00:20