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_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 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 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
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.
One reply to Laravel OneSignal Web Push Notification Example
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.