spatie/laravel-github-webhooks
Handle GitHub webhooks in Laravel: verify signatures, log valid calls, and dispatch jobs/events per webhook type. Includes a GitHubWebhookCall model to access payloads and queueable handlers for event-driven integrations.
ShouldQueue) and event listeners, aligning with modern microservices and async workflows.GitHubWebhookCall model encapsulates payload storage, while jobs/listeners handle business logic, reducing coupling.jobs, model, profile), allowing TPMs to adapt to specific workflows (e.g., filtering events, adding pre/post-processing logic).Route::githubWebhooks() macro abstracts routing complexity, reducing boilerplate.payload() method on GitHubWebhookCall provides dot-notation access, easing data extraction.verify_signature config). Misconfiguration (e.g., wrong GITHUB_WEBHOOK_SECRET) could expose the app to spoofing. Risk Mitigation: Use environment variables and validate secrets during deployment.pull_request events). Storing raw payloads in the DB (github_webhook_calls) may bloat storage. Risk Mitigation: Implement payload truncation or offload to S3 for large events.processed_at check in custom jobs or use Laravel’s unique() queue directive.*) handlers catch all events but may lead to maintenance overhead. Risk Mitigation: Start with specific handlers (e.g., issues.opened) and refactor as needed.github_webhook_calls table meets audit needs (e.g., retention policies).ProcessGitHubWebhookJob or overriding GitHubWebhookCall may be needed.GitHubWebhookCall or using GitHub’s webhook testing tools is recommended.failed_jobs table or a monitoring tool (e.g., Sentry).GitHubWebhookCall).composer.json constraints). No major version conflicts expected.github_webhook_calls. Schema is published via migrations.php artisan queue:work) is running to process jobs.api.php). Avoids session/CSRF issues by excluding the webhook route from VerifyCsrfToken.composer require spatie/laravel-github-webhooks
php artisan vendor:publish --provider="Spatie\GitHubWebhooks\GitHubWebhooksServiceProvider" --tag="github-webhooks-config"
php artisan vendor:publish --provider="Spatie\GitHubWebhooks\GitHubWebhooksServiceProvider" --tag="github-webhooks-migrations"
php artisan migrate
GITHUB_WEBHOOK_SECRET in .env (from GitHub repo settings).config/github-webhooks.php (start with a wildcard * for testing).// routes/api.php
Route::githubWebhooks('github/webhook');
/github/webhook.ngrok:
ngrok http 8000
Then configure GitHub to send to https://<ngrok-subdomain>.ngrok.io/github/webhook.* → HandleAllWebhooksJob) for initial testing.issues.opened, pull_request.closed).Monolog) for webhook processing.php artisan model:prune).github-webhooks.php) reduces drift risk. Use environment variables for secrets.github_webhook_calls table before major updates.github_webhook_calls table for failed events (exception column).telescope:install for deeper request inspection.config/logging.php for webhook processing.GITHUB_WEBHOOK_SECRET matches GitHub’s setting.push with large repos), consider:
github_webhook_calls table grows with volume. Optimize with:
created_at and event.model:prune command).| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Invalid webhook signature | Rejected by package (500 error) | Validate GITHUB_WEBHOOK_SECRET; use verify_signature: false only in dev. |
| Queue worker crashes |
How can I help you explore Laravel packages today?