Laravel 10|9|8 OneSignal Web Push Notification Example

Laravel 10|9|8 OneSignal Web Push Notification Example

Laravel 10|9|8 oneSignal web push notification (🔔) example. In this tutorial, you will learn how to integrate and use oneSignal in Laravel 10|9|8 apps to send web push notifications 🔔.

First of all, please visit the https://onesignal.com/ website then create an account here and get secret id and key to creating Laravel send web push notifications using onesignal.

Laravel 10|9|8 OneSignal Web Push Notification (🔔) Example

Steps to send web push notifications from the Laravel application using the OneSignal messaging service

  • Step 1 – Install Laravel App
  • Step 2 – Setup Database with Laravel App
  • Step 3 – Install OneSignal Package
  • Step 4 – Setup OneSignal with Laravel App
  • Step 5 – Send Push Notification
  • Step 6 – Run Development Server

Step 1 – Install Laravel App

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

composer create-project --prefer-dist laravel/laravel push-notification

Step 2 – Setup Database with Laravel App

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 to send web push notifications (🔔) in laravel 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 – Setup OneSignal with Laravel App

Once you have installed a onesignal web push notification package in the laravel app. Next, open config/app.php file and add service providers and aliases into app.php file.

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 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 the terminal to start the development server:

php artisan serve

Conclusion

Laravel oneSignal web push notification example. In this tutorial, you have learned how to use oneSignal in laravel 10|9|8 app to send web push notifications 🔔.

Recommended Laravel Posts

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.

One reply to Laravel 10|9|8 OneSignal Web Push Notification Example

  1. I’ve been following your blog for quite some time now, and I love your content and the lessons you share with your readers.

    Every time I read a post, I feel like I’m able to take a single, clear lesson away from it, which is why I think it’s so great.

Leave a Reply

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