App, Player, and Notification classes aligns with Laravel’s service-oriented architecture, enabling clean integration into existing modules (e.g., NotificationService, UserDeviceService).OrderCreated → send notification via NotificationService).queue:work could mitigate this, but the SDK itself doesn’t support async.new OneSignal($authKey)) can be integrated into Laravel’s IoC container via binding:
$this->app->bind(OneSignal::class, function ($app) {
return new OneSignal(config('services.onesignal.auth_key'));
});
config/services.php:
'onesignal' => [
'auth_key' => env('ONESIGNAL_AUTH_KEY'),
'app_id' => env('ONESIGNAL_APP_ID'),
'rest_key' => env('ONESIGNAL_REST_KEY'),
],
OneSignal::sendNotification()).HttpClient as a drop-in replacement (see Integration Approach).php-compat) or polyfills.| Risk Area | Impact | Mitigation Strategy |
|---|---|---|
| OneSignal API v1 Deprecation | High | Abstract SDK behind a facade; plan to migrate to Laravel’s HTTP client or a maintained SDK. |
| PHP 8.x Incompatibility | Medium | Fork SDK or use Laravel’s HTTP client to bypass SDK entirely. |
| Guzzle v6 Deprecation | Medium | Polyfill Guzzle or replace with Laravel’s HTTP client. |
| No Async Support | Low (for most apps) | Use Laravel queues to batch async notifications. |
| Lack of Testing | Medium | Add PHPUnit tests for critical paths (e.g., notification creation, device registration). |
| No Webhook Support | Medium | Implement a Laravel route to handle OneSignal webhooks separately. |
NotificationSent event after sending via the SDK to log analytics or update user models.HttpClient for direct OneSignal v2 API integration. This eliminates dependency risks and aligns with modern Laravel practices.
// Example: Send a notification using Laravel HttpClient
use Illuminate\Support\Facades\Http;
$response = Http::withHeaders([
'Authorization' => 'Basic ' . base64_encode(config('services.onesignal.app_id') . ':' . config('services.onesignal.rest_key')),
'Content-Type' => 'application/json',
])->post('https://onesignal.com/api/v1/notifications', [
'app_id' => config('services.onesignal.app_id'),
'include_player_ids' => [$deviceId],
'contents' => ['en' => 'Your notification message'],
]);
// config/app.php
'bindings' => [
NNV\OneSignal\OneSignal::class => function ($app) {
return new NNV\OneSignal\OneSignal(
config('services.onesignal.auth_key'),
config('services.onesignal.app_id'),
config('services.onesignal.rest_key')
);
},
];
App\Services\OneSignalService to encapsulate SDK usage:
namespace App\Services;
use NNV\OneSignal\OneSignal;
use NNV\OneSignal\API\Notification;
class OneSignalService {
public function __construct(private OneSignal $oneSignal) {}
public function sendNotification(array $data): array {
$notification = new Notification($this->oneSignal);
return $notification->create($data)->response;
}
}
AppServiceProvider:
public function register() {
$this->app->bind(OneSignalService::class, function ($app) {
return new OneSignalService($app->make(OneSignal::class));
});
}
Notification facade).| Component | Compatibility Status | Workaround |
|---|---|---|
| PHP 8.1+ |
How can I help you explore Laravel packages today?