Skip to main content
ladumor/one-signal

Laravel One Signal

Send push, email and SMS notifications from Laravel, and manage users, aliases and subscriptions, through one facade instead of hand-written HTTP calls.

License
MIT
Language
PHP
Last push
January 31, 2026
GitHub stars
122
Forks
24
Composer installs
375.3K
composer require ladumor/one-signal

Laravel One Signal is Laravel Wrapper for One Signal. One Signal is a great platform for send a push notification to your users. This package mentions in One Signal's official Document. you can see here

Give a Star if this package realy usefull to you. it's free

here are video tutorials

How to install and how to implement notifications and devices APIs.

Watch on YouTube (opens in a new tab)

how to implement Segment and Apps APIs.

Watch on YouTube (opens in a new tab)

Requirements.

v2.0.0 is released with new features and new APIs with latest version of one signal. this version is supported in laravel 8 and more. if you want to use this package in laravel 7 or lower version than you can use v1.0.0.

Installation

Install the package by the following command

bash
composer require ladumor/one-signal:2.0.2

Publish the config file

Run the following command to publish config file,

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

Add Provider

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

php
Ladumor\OneSignal\OneSignalServiceProvider::class,

Add Facade

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

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

Add ENV data

Add your api keys and OneSignal app id to your .env,

ini
ONE_SIGNAL_APP_ID=XXXXXX-XXXXXX-XXXXXX-XXXXXX  (YOUR APP ID)
ONE_SIGNAL_AUTHORIZE=XXXXXX                    (REST API KEY)
ONE_SIGNAL_AUTH_KEY=XXXXXXX                    (YOUR USER AUTH KEY)

You can call them into your code with,

Usage

Send Notification

Push

For send push notification, use the sendPush method by calling, you can refer this docs for more fields details.

php
$fields['include_aliases']['onesignal_id'] = ['xxxxxxxx-xxxx-xxx-xxxx-yyyyyyyyy'];
$message = 'hey!! this is test push.!'

OneSignal::sendPush($fields, $message);

Optionally, you can obtain the id of the notification like this,

php
$notificationID = OneSignal::sendPush($fields, $message);
echo $notificationID["id"];

SMS

For send SMS notification, use the sendSMS method by calling,

php
$fields['include_aliases']['onesignal_id'] = ['xxxxxxxx-xxxx-xxx-xxxx-yyyyyyyyy'];
OR
$fields['include_phone_numbers'] = ['+15558675310'];

$fields['sms_from']= "+15558675309";

$message = 'hey!! this is test SMS.!'

OneSignal::sendSMS($fields, $message);

EMAIL

Ensure your Email setup is complete. For send Email notification, use the sendEmail method by calling, see more payload param here

php
$fields = [
   'email_from_name' => 'Shailesh',
   'email_from_address' => "sml@gmail.com",
   'email_reply_to_address' => "reply@gmail.com",
   'email_subject' => "Welcome to Cat Facts",
   'email_body' => "html>Welcome to Cat Facts</html>",
   'disable_email_click_tracking' => true,
   'include_unsubscribed' => true
];

$fields['include_aliases']['onesignal_id'] = ['xxxxxxxx-xxxx-xxx-xxxx-yyyyyyyyy'];
OR
$fields['include_email_tokens'] = ['sample@gmail.com'];

OneSignal::sendEmail($fields);

Customise Contents

You can customise a contents and pass it in fields. message does not required when you pass contents

php
$fields['include_aliases']['onesignal_id'] = ['xxxxxxxx-xxxx-xxx-xxxx-yyyyyyyyy'];
or
$fields['include_aliases']['external_id'] = ['xxxxxxxx-xxxx-xxx-xxxx-yyyyyyyyy'];

$fields['contents'] = array(
                          "en" => 'English Message',
                          "es" => 'Spanish Message',
                      );
OneSignal::sendPush($fields);

Get Single Notification

For retrieve single notification, use the viewMessage method with id param by calling,

php
OneSignal::viewMessage($notificationId);

You can check here return response format.

Get All Notifications

For retrieve all notifications, use the viewMessages method by calling,

code
OneSignal::viewMessages();

Cancel Notification

To cancel a notification, use the cancelNotification method by calling,

php
$notificationID = 'xxxxxxxx-xxxx-xxx-xxxx-yyyyyyyyy';

OneSignal::cancelNotification($notificationID);

Notification History

For retrieve notification History, use the getMessageHistory method by calling,

php
$notificationID = 'xxxxxxxx-xxxx-xxx-xxxx-yyyyyyyyy';
$params = [
    'events' => 'sent', // required
    'email' => 'sample@gmail.com', // optional, he email address in which to deliver the report.
];

OneSignal::getMessageHistory($notificationID, $params);

Start Live Activity

This API lets you start a Live Activity by sending a Push Notification., use the startLiveActivity method by calling, See for more params here

php
$params = [
    'activity_id' => '217aae2b-42ee-4097-bc3f-b7a6e9d15b9b'
];

OneSignal::startLiveActivity($activityType, $params);

Update Live Activity

Make updates and terminate running Live Activities, use the updateLiveActivity method by calling, See for more params here

injectablephp
    $params = [
        'event' => 'update'
    ];

    OneSignal::updateLiveActivity($params);

Create User

For register a new user in OneSignal’s system, use the createUser method by calling,

injectablephp

$params = [
        'properties' => [
            "tags" => [
                "foo"  => "bar",
                "this" => "that"
            ],
            "language"     =>  "en",
            "timezone_id"  =>  "America/Los_Angeles",
            "lat"          =>  37.7749,
            "long"         =>  -122.4194,
            "country"      =>  "US",
            "first_active" =>  1589788800,
            "last_active"  =>  1589788800,
            "purchases"    =>  0,
            "ip"           =>  3232235777
        ],
        'identity' = [
            "external_id"    => "An ID, defined by you, to refer to this user in the future",
            "facebook_id"    =>  "user_facebook_id",
            "amplitude_id"   =>  "user_amplitude_id",
            "mixpanel_id"    => "user_mixpanel_id",
            "custom_alias_N" =>  "An alternative ID you'll want for retrieving this user's profile data and tags"
        ],
        'subscriptions' => [
            [
                "type" => "Email",
                "token" =>  "sample@email.com",
                "enabled" => true,
            ],
            [
                "type" => "SMS",
                "token" =>  "phone_number_in_E.164_format",
                "enabled" => true,
            ],
            [
                 "type"=>  "iOSPush",
                 "token"=>  "20bdb8fb3bdadc1bef037eefcaeb56ad6e57f3241c99e734062b6ee829271b71",
                 "enabled"=>  true,
                 "notification_types"=>  1,
                 "session_time"=> 98,
                 "session_count"=> 6,
                 "sdk"=>  "",
                 "device_model"=>  "iPhone 14",
                 "device_os"=> "18.0",
                 "rooted"=>  false,
                 "test_type"=>  1,
                 "app_version"=>  "5.1.7",
                 "web_auth"=>  "",
                 "web_p256"=> : ""
            ]
        ];
    
    OneSignal::createUser($params);

View User

For retrieve a user including aliases, properties, and subscriptions, use the viewUser method by calling,

injectablephp
    OneSignal::viewUser($onesignalId, $aliasId);

Update User

For update a user’s properties, tags, and subscriptions, use the updateUser method by calling, You can refer here for more detail about $params

injectablephp
    OneSignal::updateUser($onesignalId, $aliasId, $params);

Delete User

Delete a user including all associated properties, subscriptions, and identity. use the deleteUser method by calling,

injectablephp
    OneSignal::deleteUser($onesignalId, $aliasId);

View User Identity

Retrieve a user’s identity, use the viewUserIdentity method by calling,

injectablephp
    OneSignal::viewUserIdentity($onesignalId, $aliasId);

View User Identity By Sponsorship

Retrieve a user’s identity by subscription, use the viewUserIdentityBySubscription method by calling,

injectablephp
    OneSignal::viewUserIdentityBySubscription($subscriptionId);

Create Alias

Create an alias for a user, use the createAlias method by calling, Refer docs here for more details

injectablephp
    $params = [
        'external_id'  => "",
        'onesignal_id' => "",
    ];
    
    OneSignal::createAlias($onesignalId, $aliasId, $params);

Create Alias by subscription

Create an alias for a user by subscription, use the createAliasBySubscription method by calling, Refer docs here for more details

injectablephp
    $params = [
        'external_id'  => "",
        'onesignal_id' => "",
    ];
    
    OneSignal::createAliasBySubscription($subscriptionId, $params);

Delete Alias

Delete an alias for a user, use the deleteAlias method by calling, Refer docs here for more details

injectablephp
    OneSignal::deleteAlias($onesignalId, $aliasId, $aliasLabelToDelete);

Create Subscription

Add a new subscription to your user. use the createSubscription method by calling, Refer docs here for more body params

injectablephp
    $fields = [
        'subscription'  => [],
    ];
    
    OneSignal::createSubscription($fields);

Update Subscription

Update an existing subscription, use the updateSubscription method by calling, Refer docs here for more details

injectablephp
     $fields = [
        'subscription'  => [],
    ];
    
    OneSignal::updateSubscription($subscriptionId, $fields);

Delete Subscription

Delete an existing subscription, use the deleteSubscription method by calling, Refer docs here for more details

injectablephp
    OneSignal::deleteSubscription($subscriptionId);

Transfer Subscription

Transfer a subscription to a different user, use the transferSubscription method by calling, Refer docs here for more details

injectablephp
    $fields = [
        'identity'  => [],
    ];
    
    OneSignal::transferSubscription($subscriptionId, $fields);

Unsubscribe Notification

Unsubscribe a user from a notification, use the unsubscribeNotification method by calling, Refer docs here for more details

injectablephp
    OneSignal::unsubscribeNotification($notificationId, $token);

Create Template

Create a template for push, email and sms, use the createTemplate method by calling, Refer docs here for push, email and sms template

injectablephp
    $fields = [
        'name'  => "",
        'content' => [
            "en": "English Message" 
        ],
        "sms_from"=>"+1234567890",
         "isSMS"=> true,
    ];
    
    OneSignal::createTemplate($fields);

Update Template

update a template for push, email and sms, use the updateTemplate method by calling, Refer docs here for push, email and sms template

injectablephp
    $fields = [
        'name'  => "",
        'content' => [
            "en": "English Message" 
        ],
        "sms_from"=>"+1234567890",
        "isSMS"=> true,
    ];
    
    OneSignal::updateTemplate($templateId, $fields);

View Template

For retrieve a template, use the viewTemplate method by calling,

injectablephp
    OneSignal::viewTemplate($templateId);

View Templates

For retrieve all templates, use the viewTemplates method by calling,

injectablephp
    $params = [
        'limit' => 10,
        'offset' => 0,
        'channel' => 'push',
     ];
     
    OneSignal::viewTemplates($params);

Delete Template

For delete a template, use the deleteTemplate method by calling,

injectablephp
    OneSignal::deleteTemplate($templateId);

Copy Template

For transfer a template, use the copyTemplate method by calling,

injectablephp
    $fields = [
        'target_app_id' => "",
    ];
    
    OneSignal::copyTemplate($templateId, $fields);

Create Segment

For add a new segment in your application, use the createSegment method by calling,

php
 $fields = [
         'name' => 'iOS, Android, Web',
         "filters" => array("field" => "device_type", "relation" => "=", "value" => "Android"),
     ];

return OneSignal::createSegment($fields);

You can check here supported parameters and guide.

code
OneSignal::deleteSegment('YOUR_SEGMENT_ID')

Delete Segment

You can check here for more guide.

Apps

Note*: Auth key must be set in one-signal.php how to get auth_key?

View Apps

View the details of all of your current OneSignal apps

php
 $apps = OneSignal::getApps();

You can check here api response.

View App

View the details of single of your current OneSignal app or other app by passing app id.

php
 // It's return default site which is configured in config.
 $app = OneSignal::getApp();

 // you can specify app id as wel but it's optional
 $app = OneSignal::getApp('YOUR_APP_ID');

You can check here api response.

Create App

Creates a new OneSignal app.

php
 $fields = array(
        'name' => "TestByMe"
    );

 OneSignal::createApp($fields);

You can check here supported parameters and guide.

Update App

Update a new OneSignal app.

php
 $fields = array(
        'name' => "TestByMe"
    );

 OneSignal::updateApp($fields);
 // you can pass second param as a appId if you want to update other app.. default take from config.

You can check here supported parameters and guide.

View Outcomes

View the details of all the outcomes associated with your app.

php
 $fields = array(
        'outcome_names'       => "os__click.count",
        'outcome_time_range'  => '1h',
        'outcome_platform'    => 0,
        'outcome_attribution' => 'direct'
    );

 OneSignal::getOutcomes($fields);   // with params
 OneSignal::getOutcomes();  // without any params
 // you can pass params in this method, it's optional.

You can check here supported parameters and guide.

User Device

Watch on YouTube (opens in a new tab)

You can generate a User Device APIs with just one command,

injectablephp
php artisan one-signal.userDevice:publish

this command generate following files,

  • UserDeviceAPIController
  • UserDeviceAPIRepository
  • UserDevice (model)
  • Migration

Also, do not forget to add following routes in to the api.php file.

injectablephp
use App\Http\Controllers\API\UserDeviceAPIController;
injectablephp
  Route::post('user-device/register', [UserDeviceAPIController::class, 'registerDevice']);
  Route::get('user-device/{playerId}/update-status', [UserDeviceAPIController::class, 'updateNotificationStatus']);

Change Log

Please see Change Log here

License

The MIT License (MIT). Please see License File for more information

This page shows the project README and refreshes about once an hour. Read it on GitHub (opens in a new tab).

More open source

All projects →
  • ladumor/laravel-pwa

    Laravel PWA

    Generates the manifest, service worker, icons and splash screens for a Laravel site, then adds offline form sync and an install prompt you control.

    272
    Stars
    48
    Forks
    397.1K
    Installs
    composer require ladumor/laravel-pwa
  • ladumor/laravel-swagger

    Laravel Swagger

    Generates the Swagger file for your application and publishes the documentation view, so your API docs are one route away.

    23
    Stars
    1
    Forks
    7.6K
    Installs
    composer require ladumor/laravel-swagger