- How do I set up the Oh Dear webhook endpoint in Laravel using this package?
- First, add the `VerifyOhDearWebhook` middleware to your route in `routes/web.php` or `routes/api.php`. Then, configure your Oh Dear dashboard to send webhooks to this endpoint. The package automatically validates signatures using your `OHDEAR_WEBHOOK_SECRET` from `.env`. Example route: `Route::post('/ohdear-webhook', [OhDearWebhookController::class, 'handle'])->middleware('verify.ohdear');`
- Which Laravel versions and PHP versions does this package support?
- This package is optimized for Laravel 10+ and requires PHP 8.1 or higher. It leverages modern Laravel features like typed properties and enums, so older versions may not be fully compatible. Check the package’s `composer.json` for exact version constraints before installing.
- Can I process Oh Dear webhooks asynchronously using Laravel queues?
- Yes, the package integrates seamlessly with Laravel queues. After validating the webhook, dispatch a job like `OhDearWebhookEvent::dispatch($payload)` in your controller. Configure your queue connection (e.g., Redis, database) in `.env` and ensure the job class implements `ShouldQueue`.
- How do I handle different Oh Dear webhook events (e.g., uptime alerts, SSL issues)?
- The package maps webhook events to dedicated classes or listeners. Extend `OhDearWebhookEvent` or create custom listeners for specific events. For example, register a listener in `EventServiceProvider` like `OhDearUptimeAlert::class => [OhDearUptimeAlertHandler::class, 'handle']`. Each listener can then trigger domain-specific logic.
- What happens if Oh Dear retries a webhook multiple times? Will my app process duplicates?
- The package doesn’t include built-in deduplication, so retried webhooks may trigger duplicate processing. To prevent this, implement a `webhook_attempts` table or use Laravel’s `unique()` validation rule in a `webhook_log` table. Alternatively, use Laravel’s `afterCommit` hook to ensure idempotency for critical actions.
- How can I test Oh Dear webhook handling in my Laravel app?
- Use `mockwebhooks.com` or Laravel’s `HttpTests` to simulate webhook payloads. Create a test route like `webhook.test` and assert the package’s `OhDearWebhook::parse($request)` method validates and processes payloads correctly. For unit tests, mock the `OhDearWebhookEvent` and verify dispatched jobs or listeners.
- Is this package secure? How does it prevent spoofed webhook requests?
- Security is handled via HMAC signature validation. The package checks each incoming request against your `OHDEAR_WEBHOOK_SECRET` from `.env` using Laravel’s `hash_hmac`. Ensure your secret is never hardcoded and rotate it periodically in Oh Dear’s dashboard. Always use HTTPS for your webhook endpoint.
- Can I use this package in a load-balanced Laravel setup with multiple instances?
- Yes, but you’ll need to handle potential duplicate processing across instances. Use a centralized queue (e.g., Redis) and implement deduplication logic, such as a database-backed `webhook_attempts` table. Alternatively, leverage Laravel’s `unique()` rule or a distributed lock (e.g., Redis) to ensure only one instance processes a webhook.
- What if Oh Dear updates its webhook payload structure? Will this package break?
- The package doesn’t enforce strict payload schema validation by default, so Oh Dear’s API changes could cause issues. Mitigate this by implementing a `payload_schema_validator` trait or middleware to check for required fields (e.g., `incident_type`, `service_id`). Monitor Oh Dear’s changelog and update your validation logic accordingly.
- Are there alternatives to this package for handling Oh Dear webhooks in Laravel?
- For basic webhook handling, you could manually validate signatures and parse payloads using Oh Dear’s API docs. However, this package offers Laravel-native integration with events, queues, and middleware, reducing boilerplate. If you need broader webhook support (e.g., for multiple services), consider `spatie/laravel-webhook-client`, though it lacks Oh Dear-specific optimizations.