Download the PHP package yashcli/onesignal-notifier without Composer
On this page you can find all versions of the php package yashcli/onesignal-notifier. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download yashcli/onesignal-notifier
More information about yashcli/onesignal-notifier
Files in yashcli/onesignal-notifier
Package onesignal-notifier
Short Description A comprehensive OneSignal notification package for Laravel
License MIT
Homepage https://github.com/yashcli/onesignal-notifier
Informations about the package onesignal-notifier
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
- ✅ Complete OneSignal API Support - All features from the OneSignal API documentation
- ✅ 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 & Segments - Advanced targeting with filters and segments
- ✅ Buttons & 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
- PHP: 8.0 or higher
- Laravel: 8.0, 9.0, 10.0, 11.0, or 12.0
Installation
1. Install the package
2. Publish the configuration file
3. Configure your OneSignal credentials
Add your OneSignal credentials to your .env file:
Configuration
The configuration file config/onesignal-notifier.php contains all the settings:
Usage
Basic Usage
Using the Facade
Laravel Notifications
Create a notification class:
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:
You can also specify a custom API URL as the third argument if needed.
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:
How it works:
- If you do not specify recipient IDs in your notification class, the package will automatically use the value from
routeNotificationForOneSignalon the notifiable model. - This works for player IDs, subscription IDs, external user IDs, email, and tags.
Example:
Advanced Features
Images and Icons
Priority and TTL
Platform-Specific Settings
iOS Settings
Android Settings
Huawei Settings
Targeting Options
Subscription IDs (Recommended)
External User IDs
OneSignal IDs
Player IDs (Deprecated)
Buttons and Actions
Scheduling
Filters and Segments
Custom Data
URLs and Deep Linking
Silent Notifications
Error Handling
The package provides comprehensive error handling:
API Reference
Core Methods
| Method | Description |
|---|---|
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
| Method | Description |
|---|---|
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
| Method | Description |
|---|---|
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
| Method | Description |
|---|---|
setImages(array $images) |
Set images for different platforms |
setIcons(array $icons) |
Set icons for different platforms |
setIosAttachments(array $attachments) |
Set iOS attachments |
Action Methods
| Method | Description |
|---|---|
setButtons(array $buttons) |
Set buttons for mobile apps |
setWebButtons(array $buttons) |
Set web buttons |
Filter and Segment Methods
| Method | Description |
|---|---|
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
| Method | Description |
|---|---|
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
| Method | Description |
|---|---|
send() |
Send the notification |
getPayload() |
Get the current payload |
reset() |
Reset the payload to initial state |
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
This package is open-sourced software licensed under the MIT license.
Support
For support, please open an issue on GitHub or contact the maintainer.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
All versions of onesignal-notifier with dependencies
illuminate/notifications Version 5.*|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0|^12.0
illuminate/support Version 5.*|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0|^12.0
guzzlehttp/guzzle Version ^7.0