Laravel Firebase Push Notification to Android and IOS App Example
By Hardik Savani October 30, 2021 Category : LaravelPlayUnmuteLoaded: 1.20%FullscreenHi All,
In this example, you will learn laravel push notification to android and ios firebase. We will look at example of laravel firebase push notification android. i would like to show you laravel push notification android. if you want to see example of laravel push notifications ios android then you are a right place.
Today, i will give you simple example of send firebase push notification to android and ios app a using laravel. you can also use in laravel 6, laravel 7, laravel 8 and laravel 9 version.
Here, i will give you very simple step to sending push notification to android and ios app using laravel application. so basically your front-end mobile application provides you device token and you will store on database. Then you will use that device token to sending push notification using firebase laravel. so let's follow bellow steps:
Preview:
Step 1: Create Firebase Project and App
In first step, we have to go Firebase Console and create a project. then you have to create web app on that project as like i added bellow screenshot:
After created successfully created app we will go to setting page and get server api key as like bellow screen shot:
You can copy that key and add on env file as bellow:
.env
FCM_SERVER_KEY=XXXXX
Step 2: Create Route
Here, we need to add some routes to send push notification so let's add that route in web.php file.
routes/web.php
<?php use Illuminate\Support\Facades\Route;use App\Http\Controllers\NotificationController; /*|--------------------------------------------------------------------------| Web Routes|--------------------------------------------------------------------------|| Here is where you can register web routes for your application. These| routes are loaded by the RouteServiceProvider within a group which| contains the "web" middleware group. Now create something great!|*/ Route::get('push-notification', [NotificationController::class, 'index']);Route::post('sendNotification', [NotificationController::class, 'sendNotification'])->name('send.notification');