Laravel OneSignal Web Push Notification Example

Laravel OneSignal Web Push Notification Example

Laravel 8 one signal web push notification example. In this tutorial, you will learn how to use oneSignal in laravel 8 app for sending push notification. And as well as learn how to integrate one signal web push notification in laravel 8 app.

First of all, please visit the https://onesignal.com/ web site then create an account here and get secret id and key for sending web push notifications.

How to use One Signal in Laravel

Just follow the following steps and use one signal in laravel app for sending push notification:

  • Step 1 – Install Laravel 8 App
  • Step 2 – Connecting App to Database
  • Step 3 – Install OneSignal Package
  • Step 4 – Configure OneSignal Package
  • Step 5 – Send Push Notification
  • Step 6 – Run Development Server

Step 1 – Install Laravel 8 App

First of all, open terminal and execute the following command on terminal to install or download Laravel 8 app:

composer create-project --prefer-dist laravel/laravel Laravel-QR-Code

Step 2 – Connecting App to Database

In this step, open .env and configure database details for connecting app to database:

 DB_CONNECTION=mysql 
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=here your database name here
DB_USERNAME=here database username here
DB_PASSWORD=here database password here

And as well as, configure a .env file with following keys:

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

Step 3 – Install OneSignal Package

In this step, Execute the following command terminal to install onesignal package for send web push notification in laravel 8 app:

composer require ladumor/one-signal

Publish the config file
Run the following command to publish config file,

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

Step 4 – Configure OneSignal Package

After successfully install a onesignal web push notification package in the laravel app. Next, open config/app.php file and add service provider and aliases.

Add Provider
Add the provider to your config/app.php into provider section if using lower version of Laravel,

Ladumor\OneSignal\OneSignalServiceProvider::class,

Add Facade
Add the Facade to your config/app.php into aliases section,

'OneSignal' => \Ladumor\OneSignal\OneSignal::class,

Step 5 – Send Push Notification

In this step, you need to checkout this code to send a push notification in laravel 8 app using oneSignal web push notification:

use Ladumor\OneSignal\OneSignal;
$fields['include_player_ids'] = ['xxxxxxxx-xxxx-xxx-xxxx-yyyyy']
$message = 'hey!! This is a test push.!'
OneSignal::sendPush($fields, $message);

Step 6 – Run Development Server

Now, execute the following command on terminal to start development server:

php artisan serve

Conclusion

Laravel 8 one signal web push notification example. In this tutorial, you have learned how to use oneSignal in laravel 8 app for sending push notification.

Recommended Laravel Posts

Recommended:-Laravel Try Catch

AuthorAdmin

My name is Devendra Dode. I am a full-stack developer, entrepreneur, and owner of Tutsmake.com. I like writing tutorials and tips that can help other developers. I share tutorials of PHP, Python, Javascript, JQuery, Laravel, Livewire, Codeigniter, Node JS, Express JS, Vue JS, Angular JS, React Js, MySQL, MongoDB, REST APIs, Windows, Xampp, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL and Bootstrap from a starting stage. As well as demo example.

Leave a Reply

Your email address will not be published. Required fields are marked *