Notification channel system, ensuring seamless integration with existing Laravel applications (e.g., Notification::route(), event() triggers). This aligns with Laravel’s event-driven architecture and reduces boilerplate for push notifications.$notification->setTitle()->setSubtitle()) mirrors Laravel’s Eloquent and Notification patterns, improving developer familiarity and reducing cognitive load.string, array, bool) reduces runtime errors and IDE support (e.g., autocompletion, type hints), critical for large-scale applications.sent, failed) for observability and extensibility, enabling custom logic (e.g., analytics, retries).vendor:publish step is standard for Laravel packages.database, redis) for async delivery..env).composer require lepresk/laravel-onesignal
php artisan vendor:publish --tag=onesignal-config
.env:
ONESIGNAL_APP_ID=your_app_id
ONESIGNAL_REST_API_KEY=your_key
ONESIGNAL_REGION=us2 # or eu1, etc.
config/onesignal.php (e.g., default headers, timeout, logging).App\Providers\RouteServiceProvider to bind notification routes if using dynamic recipients.NotificationSent events) with Laravel’s listen() method.users pivot table).Notification facade.use Lepresk\OneSignal\OneSignalChannel;
Notification::route('onesignal', $user->device_token)
->notify(new PushNotification('Hello!'));
sent → log to a database).OneSignalMessage class for non-standard payloads.composer why-not lepresk/laravel-onesignal to check for conflicts..env and use Laravel’s config caching to avoid runtime overrides.'log' => [
'enabled' => true,
'channel' => 'onesignal',
],
config/onesignal.php to surface OneSignal-specific errors (e.g., invalid tokens).database, redis) to offload notification sends and avoid timeouts.
Notification::route('onesignal', $token)->delay(now()->addMinute())->notify($notification);
| Failure Scenario | Impact | Mitigation |
|---|---|---|
| OneSignal API downtime | Notifications fail silently | Implement retry logic with exponential backoff; fallback to email/SMS. |
| Invalid device tokens | High error rates | Validate tokens before sending; use OneSignal’s check_device_id endpoint. |
| Payload malformation | Notifications not delivered | Unit test payloads with OneSignal’s sandbox; use the fluent API for consistency. |
| Queue worker crashes | Delayed/notifications | Monitor queue jobs; set up dead-letter queues. |
| Rate limiting | Throttled requests | Implement batching; upgrade OneSignal plan if needed. |
// Send to all users with a device token
User::whereNotNull('device_token')->each(fn ($user) =>
$user->notify(new PushNotification('Update'))
);
// Segmented send (e.g., users in a region)
$tokens = User::where('region', 'EU')->pluck('device_token');
OneSignal::sendToTokens($tokens, 'EU Campaign');
How can I help you explore Laravel packages today?