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 – Configure Database with App
- Step 3 – Install OneSignal Package
- Step 4 – Configure OneSignal Package
- 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 – Configure Database with App
In this step, open .env and configure database details for connecting app to database:
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 – Configure OneSignal Package
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 the provider to your config/app.php into provider section if using lower version of Laravel,
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
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 🔔.