Laravel OneSignal Push Notification Integrate

  • 12-11-2022
  • 1853
  • Laravel 9
  • Haresh Chauhan

Laravel Onesignal Push Notification Integrate; In this comprehensive post I will show you how to send push notifications using the OneSignal message service provider in laravel.

For sending Web push notifications using OneSingal messaging service that allows sending a push notification. We will show you how to integrate how to configure the OneSignal plugin in the laravel application and the step. Also, learn how to send and retrieve web push notifications.

Using OneSignal Push notification send I will give you all perforable guidelines to integrate into your application. Before you start integrating, go to OneSignal dashboard and create your account using your email id.

image

Step 1. Install Composer

Add OneSignal package in our laravel application using composer, Laravel OneSignal notification help us to send push notification in the laravel application. Therefore we are required to install a dependency package in the laravel application. use the below-provided command in your application and install the package.

composer require ladumor/one-signal

Step 2. Publish Config File

Now we will publish the config file in your config setting for the OneSignal. Use the below-provided command in the application. This file will help us to change the basic setting change in the OneSignal push notification. After hitting this command you will see a new generated file in the config folder in the application. This file genera with the basic setting in the OneSignal.

php artisan vendor:publish --provider="Ladumor\OneSignal\OneSignalServiceProvider"

Step 3. Add Service Provider & Facade

Now in this step, we will add the Service provider and Facade to our application. Goto config/app.php file and add a provider and facade for the OneSignal. Register both inside the facade and provider attribute as below given example.

<?php
return [
     'providers' => [
          ...
          ...
          Ladumor\OneSignal\OneSignalServiceProvider::class,
     ],
     'aliases' => [
          ...
          ...
          'OneSignal' => \Ladumor\OneSignal\OneSignal::class,
     ]
];

Step 5. Setup .env

Now it's time to update the OneSignal Auth keys in the configuration. Open the .env file of your application and paste these below provider keys in the .env file. OneSignal, Go through this link and sign in to your account and generate these keys from your account.

ONE_SIGNAL_APP_ID=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX 
ONE_SIGNAL_AUTHORIZE=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 
ONE_SIGNAL_AUTH_KEY=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Step 6. Test

Start your development server and test your create a route. First, you import and use OneSignal from the Ladumor package. Inside the route define the $fields variable. you have to pass the player id in the array variable as below given example. The $message variable will statically be called a message that you want to sing through OneSignal notification to the Users. Access method through the OneSignal Facade sends push() method. with given two arguments and defined variables.

use Ladumor\OneSignal\OneSignal; 

Route::get('/send-notification',function(){
     
     $fields['include_player_ids'] = ['xxxxxxxx-xxxx-xxx-xxxx-yyyyy'];

     $message = 'Hi! Good Morning, This is One Signel Push Notification.';

     OneSignal::sendPush($fields, $message);

     dd('Success!');
});

You can Retrieve all the notifications, you can use getNotifications() method by calling OneSignal.

OneSignal::getNotifications();

Start Your development server and send a notification.

php artisan serve

Sendgrid Email Send Tutorial Laravel/PHP/cURL Example

Queue Laravel Command Tutorial Example

Laravel 9 QR Code Generator Basic To Advanced Tutorial Example

Laravel 9 Google Drive File Upload/Store Tutorial

Web Push Notification Send Using Firebase Cloud Messaging In Laravel Tutorial Include Demo Example


We always thanks to you for reading our blogs.


dharmesh-image

Dharmesh Chauhan

(Swapinfoway Founder)

Hello Sir, We are brothers origin from Gujarat India, Fullstack developers working together since 2016. We have lots of skills in web development in different technologies here I mention PHP, Laravel, Javascript, Vuejs, Ajax, API, Payment Gateway Integration, Database, HTML5, CSS3, and Server Administration. So you need our service Please Contact Us

haresh-image

Haresh Chauhan

(Co-Founder)


We Are Also Recommending You :