PHPackages                             yashcli/onesignal-notifier - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Mail &amp; Notifications](/categories/mail)
4. /
5. yashcli/onesignal-notifier

ActiveLibrary[Mail &amp; Notifications](/categories/mail)

yashcli/onesignal-notifier
==========================

A comprehensive OneSignal notification package for Laravel

v1.0.0(9mo ago)31MITPHPPHP ^8.0

Since Jul 30Pushed 9mo agoCompare

[ Source](https://github.com/yash-cli/onesignal-notifier)[ Packagist](https://packagist.org/packages/yashcli/onesignal-notifier)[ Docs](https://github.com/yashcli/onesignal-notifier)[ RSS](/packages/yashcli-onesignal-notifier/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (5)Versions (2)Used By (0)

OneSignal Notification Package for Laravel
==========================================

[](#onesignal-notification-package-for-laravel)

A comprehensive Laravel package for sending push notifications through OneSignal with support for all features including images, priority, player\_id, subscription\_id, and more.

Features
--------

[](#features)

- ✅ **Complete OneSignal API Support** - All features from the [OneSignal API documentation](https://documentation.onesignal.com/reference/push-notification)
- ✅ **Image Support** - Set images for different platforms (big\_picture, chrome\_web\_image, etc.)
- ✅ **Priority Control** - Set notification priority levels
- ✅ **Multiple Targeting Options** - Support for player\_id, subscription\_id, external\_user\_id, OneSignal ID
- ✅ **Platform-Specific Features** - iOS, Android, Huawei, Web push specific settings
- ✅ **Scheduling** - Send notifications at specific times
- ✅ **Filters &amp; Segments** - Advanced targeting with filters and segments
- ✅ **Buttons &amp; Actions** - Interactive notifications with buttons
- ✅ **Custom Data** - Attach custom data to notifications
- ✅ **Laravel Integration** - Works seamlessly with Laravel notifications
- ✅ **Error Handling** - Comprehensive error handling with custom exceptions
- ✅ **Facade Support** - Easy access through Laravel facades

Requirements
------------

[](#requirements)

- **PHP**: 8.0 or higher
- **Laravel**: 8.0, 9.0, 10.0, 11.0, or 12.0

Installation
------------

[](#installation)

### 1. Install the package

[](#1-install-the-package)

```
composer require yashcli/onesignal-notifier
```

### 2. Publish the configuration file

[](#2-publish-the-configuration-file)

```
php artisan vendor:publish --tag=onesignal-notifier-config
```

### 3. Configure your OneSignal credentials

[](#3-configure-your-onesignal-credentials)

Add your OneSignal credentials to your `.env` file:

```
ONESIGNAL_APP_ID=your-app-id
ONESIGNAL_REST_API_KEY=your-rest-api-key
ONESIGNAL_API_URL=https://api.onesignal.com/notifications
```

Configuration
-------------

[](#configuration)

The configuration file `config/onesignal-notifier.php` contains all the settings:

```
return [
    'app_id' => env('ONESIGNAL_APP_ID'),
    'rest_api_key' => env('ONESIGNAL_REST_API_KEY'),
    'api_url' => env('ONESIGNAL_API_URL', 'https://api.onesignal.com/notifications'),

    'defaults' => [
        'priority' => 10,
        'ttl' => 259200, // 3 days in seconds
        'ios_sound' => 'default',
        'android_sound' => 'default',
        'android_channel_id' => null,
        'ios_badge_type' => 'Increase',
        'ios_badge_count' => 1,
    ],

    'platforms' => [
        'ios' => [
            'enabled' => true,
            'interruption_level' => 'active',
        ],
        'android' => [
            'enabled' => true,
            'accent_color' => '#FF0000',
        ],
        'web' => [
            'enabled' => true,
        ],
    ],
];
```

Usage
-----

[](#usage)

### Basic Usage

[](#basic-usage)

```
use YashCli\OneSignalNotifier\OneSignal;

$oneSignal = new OneSignal();

$result = $oneSignal
    ->setContent(['en' => 'Hello! This is a test notification.'])
    ->setHeading(['en' => 'Test Notification'])
    ->setSubscriptionIds(['subscription_id_1', 'subscription_id_2'])
    ->send();
```

### Using the Facade

[](#using-the-facade)

```
use YashCli\OneSignalNotifier\OneSignalFacade;

$result = OneSignalFacade::setContent(['en' => 'Hello!'])
    ->setHeading(['en' => 'Test'])
    ->setSubscriptionIds(['subscription_id_1'])
    ->send();
```

### Laravel Notifications

[](#laravel-notifications)

Create a notification class:

```
use Illuminate\Notifications\Notification;
use YashCli\OneSignalNotifier\Channels\OneSignalChannel;

class TestNotification extends Notification
{
    public function via($notifiable): array
    {
        return [OneSignalChannel::class];
    }

    public function toOneSignal($notifiable): array
    {
        return [
            'content' => ['en' => 'You have a new message!'],
            'heading' => ['en' => 'New Message'],
            'subscription_ids' => ['subscription_id_1'],
            'priority' => 10,
            'images' => [
                'big_picture' => 'https://example.com/image.jpg',
            ],
            'custom_data' => [
                'message_id' => '12345',
                'sender' => 'John Doe',
            ],
        ];
    }
}
```

### Creating a Client with Custom Credentials

[](#creating-a-client-with-custom-credentials)

If you need to send notifications using a different OneSignal App ID and REST API Key (for example, to support multiple OneSignal apps), you can create a client instance with custom credentials:

```
use YashCli\OneSignalNotifier\OneSignal;

$client = OneSignal::createClient('your-app-id', 'your-rest-api-key');

$result = $client
    ->setContent(['en' => 'Hello from a custom client!'])
    ->setHeading(['en' => 'Custom Client'])
    ->setSubscriptionIds(['subscription_id_1'])
    ->send();
```

You can also specify a custom API URL as the third argument if needed.

Recipient Resolution with routeNotificationForOneSignal
-------------------------------------------------------

[](#recipient-resolution-with-routenotificationforonesignal)

You can define a `routeNotificationForOneSignal` method on your notifiable model (e.g., User) to automatically resolve recipient IDs for notifications. This allows you to avoid specifying player IDs, subscription IDs, or external user IDs in every notification class.

**How to use:**

Add the method to your notifiable model:

```
// In your User model (or any Notifiable model)
public function routeNotificationForOneSignal()
{
    // Return a single player ID (deprecated)
    // return 'PLAYER_ID';

    // Return an array of player IDs (deprecated)
    // return ['PLAYER_ID_1', 'PLAYER_ID_2'];

    // Return subscription IDs (recommended)
    // return ['subscription_id_1', 'subscription_id_2'];

    // Return external user IDs
    // return ['include_external_user_ids' => [$this->id]];

    // Return email for OneSignal syncHashedEmail feature
    // return ['email' => $this->email];

    // Return tags for advanced targeting
    // return ['tags' => ['key' => 'device_uuid', 'relation' => '=', 'value' => $this->device_uuid]];
}
```

**How it works:**

- If you do not specify recipient IDs in your notification class, the package will automatically use the value from `routeNotificationForOneSignal` on the notifiable model.
- This works for player IDs, subscription IDs, external user IDs, email, and tags.

**Example:**

```
// User model
public function routeNotificationForOneSignal()
{
    return ['subscription_id_1', 'subscription_id_2'];
}

// Notification class (no need to specify recipient IDs)
public function toOneSignal($notifiable): array
{
    return [
        'content' => ['en' => 'You have a new message!'],
        'heading' => ['en' => 'New Message'],
        // No subscription_ids needed here!
    ];
}
```

Advanced Features
-----------------

[](#advanced-features)

### Images and Icons

[](#images-and-icons)

```
$oneSignal->setImages([
    'big_picture' => 'https://example.com/image.jpg',
    'chrome_web_image' => 'https://example.com/web-image.jpg',
    'huawei_big_picture' => 'https://example.com/huawei-image.jpg',
    'adm_big_picture' => 'https://example.com/amazon-image.jpg',
]);

$oneSignal->setIcons([
    'small_icon' => 'https://example.com/small-icon.png',
    'large_icon' => 'https://example.com/large-icon.png',
    'chrome_web_icon' => 'https://example.com/web-icon.png',
    'firefox_icon' => 'https://example.com/firefox-icon.png',
]);
```

### Priority and TTL

[](#priority-and-ttl)

```
$oneSignal->setPriority(10) // High priority
    ->setTtl(3600); // 1 hour TTL
```

### Platform-Specific Settings

[](#platform-specific-settings)

#### iOS Settings

[](#ios-settings)

```
$oneSignal->setIosInterruptionLevel('time-sensitive')
    ->setIosSound('default')
    ->setIosBadgeType('Increase')
    ->setIosBadgeCount(1)
    ->setIosCategory('message')
    ->setTargetContentIdentifier('message_123')
    ->setThreadId('chat_456')
    ->setIosRelevanceScore(5);
```

#### Android Settings

[](#android-settings)

```
$oneSignal->setAndroidAccentColor('#FF0000')
    ->setAndroidChannelId('default')
    ->setAndroidGroup('chat_messages');
```

#### Huawei Settings

[](#huawei-settings)

```
$oneSignal->setHuaweiChannelId('huawei_channel')
    ->setHuaweiCategory('message')
    ->setHuaweiMsgType('data')
    ->setHuaweiBiTag('tag1')
    ->setHuaweiAccentColor('#FF0000');
```

### Targeting Options

[](#targeting-options)

#### Subscription IDs (Recommended)

[](#subscription-ids-recommended)

```
$oneSignal->setSubscriptionIds(['subscription_id_1', 'subscription_id_2']);
```

#### External User IDs

[](#external-user-ids)

```
$oneSignal->setExternalUserIds(['user_123', 'user_456']);
```

#### OneSignal IDs

[](#onesignal-ids)

```
$oneSignal->setOneSignalIds(['1589641e-bed1-4325-bce4-d2234e578884']);
```

#### Player IDs (Deprecated)

[](#player-ids-deprecated)

```
$oneSignal->setPlayerIds(['player_id_1', 'player_id_2']);
```

### Buttons and Actions

[](#buttons-and-actions)

```
$oneSignal->setButtons([
    [
        'id' => 'accept',
        'text' => 'Accept',
        'icon' => 'https://example.com/accept-icon.png',
    ],
    [
        'id' => 'decline',
        'text' => 'Decline',
        'icon' => 'https://example.com/decline-icon.png',
    ],
]);

$oneSignal->setWebButtons([
    [
        'id' => 'view',
        'text' => 'View Details',
        'url' => 'https://yourapp.com/details',
    ],
]);
```

### Scheduling

[](#scheduling)

```
$oneSignal->setSendAfter(date('c', strtotime('+1 hour'))) // Send after 1 hour
    ->setDelayedOption('timezone') // or 'last-active'
    ->setDeliveryTimeOfDay('9:00AM');
```

### Filters and Segments

[](#filters-and-segments)

```
// Add filters
$oneSignal->addFilter('first_session', 'first_session', '>', '1')
    ->addFilter('country', 'country', '=', 'US');

// Set segments
$oneSignal->setIncludedSegments(['Subscribed Users'])
    ->setExcludedSegments(['Inactive Users']);
```

### Custom Data

[](#custom-data)

```
$oneSignal->setCustomData([
    'message_id' => '12345',
    'sender' => 'John Doe',
    'type' => 'chat',
]);

$oneSignal->setData([
    'silent' => true,
    'action' => 'refresh',
]);
```

### URLs and Deep Linking

[](#urls-and-deep-linking)

```
$oneSignal->setUrl('https://yourapp.com/messages/12345')
    ->setAppUrl('yourapp://messages/12345')
    ->setWebUrl('https://yourapp.com/web/messages/12345');
```

### Silent Notifications

[](#silent-notifications)

```
$oneSignal->setContentAvailable(true)
    ->setData(['silent' => true, 'action' => 'refresh']);
```

Error Handling
--------------

[](#error-handling)

The package provides comprehensive error handling:

```
use YashCli\OneSignalNotifier\Exceptions\OneSignalException;

try {
    $result = $oneSignal->send();
} catch (OneSignalException $e) {
    echo "OneSignal Error: " . $e->getMessage() . "\n";

    if ($e->hasInvalidAliases()) {
        echo "Invalid Aliases: " . json_encode($e->getInvalidAliases()) . "\n";
    }

    if ($e->hasInvalidPlayerIds()) {
        echo "Invalid Player IDs: " . json_encode($e->getInvalidPlayerIds()) . "\n";
    }

    echo "Errors: " . json_encode($e->getErrors()) . "\n";
}
```

API Reference
-------------

[](#api-reference)

### Core Methods

[](#core-methods)

MethodDescription`setContent(array $content)`Set notification content for different languages`setHeading(array $heading)`Set notification heading for different languages`setSubtitle(array $subtitle)`Set notification subtitle for different languages`setName(string $name)`Set notification name/template name`setTemplateId(string $templateId)`Set template ID`setCustomData(array $data)`Set custom data`setData(array $data)`Set additional data`setPriority(int $priority)`Set notification priority`setTtl(int $ttl)`Set TTL (Time To Live) in seconds`setCollapseId(string $collapseId)`Set collapse ID for grouping notifications### Targeting Methods

[](#targeting-methods)

MethodDescription`setSubscriptionIds(array $ids)`Set subscription IDs (recommended)`setExternalUserIds(array $ids)`Set external user IDs`setOneSignalIds(array $ids)`Set OneSignal IDs`setPlayerIds(array $ids)`Set player IDs (deprecated)`setIncludeAliases(array $aliases)`Set include aliases### Platform-Specific Methods

[](#platform-specific-methods)

MethodDescription`setIosInterruptionLevel(string $level)`Set iOS interruption level`setIosSound(string $sound)`Set iOS sound`setIosBadgeType(string $type)`Set iOS badge type`setIosBadgeCount(int $count)`Set iOS badge count`setAndroidAccentColor(string $color)`Set Android accent color`setAndroidChannelId(string $channelId)`Set Android channel ID`setHuaweiChannelId(string $channelId)`Set Huawei channel ID### Image and Icon Methods

[](#image-and-icon-methods)

MethodDescription`setImages(array $images)`Set images for different platforms`setIcons(array $icons)`Set icons for different platforms`setIosAttachments(array $attachments)`Set iOS attachments### Action Methods

[](#action-methods)

MethodDescription`setButtons(array $buttons)`Set buttons for mobile apps`setWebButtons(array $buttons)`Set web buttons### Filter and Segment Methods

[](#filter-and-segment-methods)

MethodDescription`setFilters(array $filters)`Set filters for targeting`addFilter(string $field, string $key, string $relation, string $value)`Add a filter`setIncludedSegments(array $segments)`Set included segments`setExcludedSegments(array $segments)`Set excluded segments### Scheduling Methods

[](#scheduling-methods)

MethodDescription`setScheduling(array $scheduling)`Set scheduling options`setSendAfter(string $dateTime)`Set send after date/time`setDelayedOption(string $option)`Set delayed option`setDeliveryTimeOfDay(string $time)`Set delivery time of day### Utility Methods

[](#utility-methods)

MethodDescription`send()`Send the notification`getPayload()`Get the current payload`reset()`Reset the payload to initial stateSystem Requirements
-------------------

[](#system-requirements)

- **PHP**: 8.0 or higher
- **Laravel**: 5.\*, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, or 12.0
- **GuzzleHTTP**: 7.0 or higher

License
-------

[](#license)

This package is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).

Support
-------

[](#support)

For support, please open an issue on GitHub or contact the maintainer.

Contributing
------------

[](#contributing)

Contributions are welcome! Please feel free to submit a Pull Request.

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance57

Moderate activity, may be stable

Popularity5

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

283d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/d6949981e27a263a9083574b2e83af1667d894aaf354b72f440e431ceb66e405?d=identicon)[yash-cli](/maintainers/yash-cli)

---

Top Contributors

[![yash-cli](https://avatars.githubusercontent.com/u/67585848?v=4)](https://github.com/yash-cli "yash-cli (1 commits)")

---

Tags

laravelnotificationsonesignalpush notificationslaravel-notificationWeb Pushlaravel-onesignal

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/yashcli-onesignal-notifier/health.svg)

```
[![Health](https://phpackages.com/badges/yashcli-onesignal-notifier/health.svg)](https://phpackages.com/packages/yashcli-onesignal-notifier)
```

###  Alternatives

[laravel-notification-channels/telegram

Telegram Notifications Channel for Laravel

1.1k3.4M35](/packages/laravel-notification-channels-telegram)[s-ichikawa/laravel-sendgrid-driver

This library adds a 'sendgrid' mail driver to Laravel.

4139.3M1](/packages/s-ichikawa-laravel-sendgrid-driver)[laravel-notification-channels/discord

Laravel notification driver for Discord.

2371.3M11](/packages/laravel-notification-channels-discord)[benwilkins/laravel-fcm-notification

Laravel FCM (Firebase Cloud Messaging) Notification Channel

210964.1k1](/packages/benwilkins-laravel-fcm-notification)[bentools/webpush-bundle

Send push notifications through Web Push Protocol to your Symfony users.

71274.3k](/packages/bentools-webpush-bundle)[laravel-notification-channels/rocket-chat

Rocket.Chat Notifications channel for Laravel 5.6+

1345.5k](/packages/laravel-notification-channels-rocket-chat)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
