Laravel 10 OneSignal Web Push Notification Integration Tutorial

Last Updated on by in Laravel

In this tutorial, you’ll learn how to integrate OneSignal with a Laravel application to send web push notifications.

Push notifications are a powerful way to keep users engaged with your application by delivering timely, relevant messages directly to their devices.

We’ll guide you through setting up OneSignal in your Laravel project, configuring your application for push notifications, and sending notifications from within your application using the OneSignal API.

To integrate one signal web push notification in laravel, you have to create an account at OneSignal using your email id or social media account and obtain the key and the secret id of OneSignal.

We’ll start by installing the OneSignal package and setting up your environment variables. Then, we’ll show you how to configure the package in your Laravel application, including setting up the necessary credentials and URL endpoints.

After that, you’ll learn how to create and send web push notifications using Eloquent models and the OneSignal package.

By the end of this tutorial, you’ll be able to send web push notifications from your Laravel application using OneSignal, enhancing user engagement and providing a better experience for your audience.

How to Use One Signal to Send Web Push Notification in Laravel 10

  • Step: 1 Create Laravel Project
  • Step: 2 Make Database Connection
  • Step: 3 Update OneSignal Auth Keys
  • Step: 4 Add OneSignal Package in Laravel
  • Step: 5 Set Up OneSignal in Laravel
  • Step: 6 Send Push Notifications
  • Step: 7 Run Laravel Application

Create Laravel Project

Before you start, make sure you have a basic laravel application is created.

If not, go ahead and execute the given below command from the terminal’s screen.

composer create-project laravel/laravel my-demo-app --prefer-dist

Further, step inside the app:

cd my-demo-app

Make Database Connection

In this second step, you will have to open the .env config file and add the database name, username and password to make the laravel and database connection.


If you are using MAMP local server in macOs; make sure to append UNIX_SOCKET and DB_SOCKET below database credentials in .env file.


Update OneSignal Auth Keys

One more, again open the .env configuration file and update OneSignal auth keys to connect laravel to OneSignal.


Add OneSignal Package in Laravel

Laravel OneSignal helps you send web push notifications to users; moreover, you can rely on its fidelity and power.

Implementing OneSignal in Laravel requires package installation in the Laravel app.

composer require ladumor/one-signal

Set Up OneSignal in Laravel

You have just installed the OneSignal package into the laravel app.

Furthermore, type the given command on the terminal and, without giving a thought, run the suggested command to publish separately create the config file.

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

Now, in the subsequent step, you have to add providers and facade inside the config/app.php file.

return [
    'providers' => [
    'aliases' => [
        'OneSignal' => \Ladumor\OneSignal\OneSignal::class,

Send Push Notifications

In a controller, you have to first import or use the OneSignal service from the Ladumor package. Inside the controller’s function, define $fields variable. You have to pass the player id in it.

The notification message var will hold the dynamic notification message; however, we passed it statistically.

Access sendPush() method via OneSignal module and in this message pass fields and notification message.

use Ladumor\OneSignal\OneSignal;

$fields['include_player_ids'] = ['xxxxxxxx-xxxx-xxx-xxxx-yyyyy']
$notificationMsg = 'Hello!! A tiny web push notification.!'
OneSignal::sendPush($fields, $notificationMsg);

To retrieve all notifications, you can use the getNotifications method by calling,


Run Laravel Application

Ultimately, you are utterly ready to start the laravel application and type recommended command to invoke the development server.

php artisan serve


Sending web push notifications from your Laravel application using OneSignal is straightforward.

By following this guide, you’ve mastered the setup and configuration, allowing you to keep users informed and engaged.

Age calculator tool

🎂✨ Discover your age in detail and with countdown to your next birthday with fun facts! 🎈🎉

Calculate your age now!
Digamber - Author

Hi, I'm Digamber Singh, a New Delhi-based full-stack developer, tech author, and open-source contributor with 10+ years' experience in HTML, CSS, JavaScript, PHP, and WordPress.