jowxidea/onesignal

A Laravel package for sending push notifications using OneSignal.

Maintainers

Package info

github.com/youssef-ahmed-cs/JowXIdea-OneSignal

pkg:composer/jowxidea/onesignal

Statistics

Installs: 3

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2026-04-27 05:42 UTC

This package is auto-updated.

Last update: 2026-04-29 18:49:48 UTC


README

A Laravel package for sending OneSignal push notifications with a minimal client API, service provider, facade, and helper function.

Features

  • Laravel auto-discovery service provider
  • Config publishing (onesignal-config)
  • Container binding (onesignal)
  • Facade (OneSignal) and helper (onesignal())
  • Send to all users, one user, many users, or named segments
  • Custom payload support and legacy-compatible notification helpers
  • Consistent HTTP response metadata for easier debugging
  • Built with Orchestra Testbench for package testing

Requirements

  • PHP 8.1+
  • Laravel 10/11/12

Installation

composer require jowxidea/onesignal

Configuration

Publish the config file:

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

Set your environment variables:

ONESIGNAL_APP_ID=your_app_id
ONESIGNAL_REST_API_KEY=your_rest_api_key
ONESIGNAL_USER_AUTH_KEY=optional_user_auth_key
ONESIGNAL_API_URL=https://onesignal.com/api/v1
ONESIGNAL_TIMEOUT=10

Usage

Send to all users

onesignal()->sendToAll(
    ['en' => 'Hello everyone'],
    ['en' => 'Announcement'],
    ['source' => 'app']
);

Send to one user

onesignal()->sendToUser(
    'player-id-123',
    ['en' => 'Hello user']
);

Send to many users

onesignal()->sendToUsers(
    ['player-id-1', 'player-id-2'],
    ['en' => 'Hello group'],
    ['en' => 'Greeting'],
    ['source' => 'app']
);

Send to a segment

onesignal()->sendToSegments(
    ['Subscribed Users'],
    ['en' => 'New update is available'],
    ['en' => 'Update']
);

Sending a custom payload

onesignal()->send([
    'included_segments' => ['All'],
    'contents' => ['en' => 'Custom payload message'],
    'headings' => ['en' => 'Custom title'],
    'data' => ['source' => 'app'],
]);

Legacy compatible methods

The client keeps compatibility with legacy OneSignal helpers while using Laravel HTTP internally:

  • sendNotificationToAll
  • sendNotificationToUser
  • sendNotificationToExternalUser
  • sendNotificationUsingTags

Using the facade

use Jowxidea\Onesignal\Facades\OneSignal;

OneSignal::sendToSegments(
    ['Subscribed Users'],
    ['en' => 'New update is available'],
    ['en' => 'Update']
);

Response format

All API methods return an array. When OneSignal responds with JSON, the decoded response is returned directly and enriched with _response metadata:

  • status — HTTP status code
  • ok — whether the response status is 200–299
  • successful — whether the response was successful
  • redirect — whether the response was a redirect
  • headers — returned response headers

For non-JSON responses, the package returns:

[
    'body' => 'raw response body',
    '_response' => [
        'status' => 200,
        'ok' => true,
        'successful' => true,
        'redirect' => false,
        'headers' => [ ... ],
    ],
]

Helper function

Use the global helper anywhere in your application:

$client = onesignal();

Testing

composer test

License

MIT