- How do I install norkunas/onesignal-php-api in a Laravel app?
- Install the package with Composer, then add a PSR-18 HTTP client and PSR-17 HTTP factories because the library requires them. For example, Composer can install norkunas/onesignal-php-api alongside symfony/http-client and nyholm/psr7. After that, create a OneSignal Config object with your app ID and auth keys, then bind the configured OneSignal client as a singleton in a Laravel service provider.
- Does norkunas/onesignal-php-api work with Laravel?
- The package is framework-agnostic PHP rather than a native Laravel package, but it fits Laravel cleanly through service providers, dependency injection, and config files. You can store OneSignal credentials in .env and config/services.php and resolve the client from the container. The technical assessment notes Laravel 9 and 10 compatibility, but you should verify the package version against your Laravel and PHP versions.
- How do I configure OneSignal app ID and REST API key in Laravel?
- Create a OneSignal Config instance with your OneSignal application ID and required auth keys, using values loaded from Laravel configuration. Put the credentials in .env, for example ONESIGNAL_APP_ID and ONESIGNAL_REST_API_KEY, and reference them from config/services.php. Register a singleton in a service provider so controllers, jobs, and tests receive the configured client through dependency injection.
- What PHP and Laravel versions does norkunas/onesignal-php-api support?
- The README says v2 examples require PHP 7.3 or newer and directs users on older PHP versions to the v1 documentation. The package also depends on a PSR-18 HTTP client and PSR-17 factories, so those implementations must be compatible with your PHP version. The assessment mentions testing with Laravel 9 and 10, but always confirm the latest package requirements before upgrading.
- How do I send push notifications with norkunas/onesignal-php-api?
- Once the OneSignal client is configured, use its notification-related API methods to create and send messages to segments, filters, or specific devices. Keep credentials out of code and build payloads in a dedicated service class or queued job for maintainability. Check the package README and OneSignal API reference for the exact method names and payload structure for your installed version.
- Can I queue OneSignal notifications asynchronously in Laravel?
- Yes. The package performs synchronous HTTP calls, so wrapping sends in Laravel queue jobs or events is the usual approach for high-volume or latency-sensitive applications. Queues let you retry failed sends, throttle delivery with tools such as Laravel Horizon, and keep web requests fast. Log job results so failed notifications can be investigated later.
- How do I test OneSignal integration in Laravel without sending real notifications?
- Inject a mocked PSR-18 HTTP client or wrap the OneSignal client in your own service and mock that service in tests. This avoids real OneSignal API calls and lets you assert that the correct payloads and credentials are used. Add feature tests for queued jobs and critical flows such as a user subscribing and receiving a notification.
- What are the production concerns for OneSignal push notifications in Laravel?
- Watch OneSignal rate limits, especially on free tiers, and use queues, throttling, and exponential backoff for large sends. OneSignal API changes can require package updates, so isolate API calls behind a service layer and monitor delivery failures. For GDPR or CCPA compliance, track opt-outs, log notification sends, and avoid sending to users who have disabled notifications.
- Is norkunas/onesignal-php-api a good alternative to a Laravel OneSignal notification channel?
- This package is a low-level OneSignal API client, while a Laravel notification channel provides tighter framework integration through the notifiable system. Choose the package when you want direct control over OneSignal endpoints, payloads, and segmentation. You can also build a custom Laravel notification channel that uses this package internally.
- How do I handle OneSignal API errors and retries with this package?
- Catch exceptions from the PSR-18 HTTP client and inspect unsuccessful OneSignal responses in your service or queued job. Implement retries with backoff through Laravel queue settings, and record failures in logs or monitoring so repeated errors are visible. For critical notifications, consider a fallback channel such as email or SMS when OneSignal delivery fails.