jowxidea / onesignal
A Laravel package for sending push notifications using OneSignal.
v1.0.0
2026-04-27 05:42 UTC
Requires
- php: ^8.1
- illuminate/http: ^10.0|^11.0|^12.0
- illuminate/support: ^10.0|^11.0|^12.0
Requires (Dev)
- orchestra/testbench: ^8.0|^9.0|^10.0
- phpunit/phpunit: ^10.5|^11.0
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:
sendNotificationToAllsendNotificationToUsersendNotificationToExternalUsersendNotificationUsingTags
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 codeok— whether the response status is 200–299successful— whether the response was successfulredirect— whether the response was a redirectheaders— 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