beyondcode/laravel-query-detector
Detect N+1 database queries in Laravel during development. Monitors queries in real time and alerts you when repeated queries indicate missing eager loading, helping you optimize performance and reduce unnecessary database calls.
--dev), avoiding runtime overhead in production.\BeyondCode\QueryDetector\Events\QueryDetected.composer require beyondcode/laravel-query-detector --dev) with auto-registration.debug mode), but stack trace analysis could add <1ms/request in high-traffic dev environments.Log) during CI, Alert in local dev.Activity::morphTo()) are known exceptions and should be pre-whitelisted?--dev).User::posts()).>3 queries/endpoint).# In GitHub Actions
- name: Check N+1 Queries
run: php artisan querydetector:check --max=3
>100 queries/minute).| Phase | Task | Owner | Dependencies |
|---|---|---|---|
| Discovery | Audit top 5 slowest endpoints for N+1 patterns. | Backend Team | Performance metrics |
| Setup | Install package, publish config, set threshold=1. |
TPM/DevOps | Laravel project |
| Whitelisting | Identify and whitelist safe relationships (e.g., User::avatar). |
Backend Team | Domain knowledge |
| CI Integration | Add N+1 check to CI pipeline. | DevOps | GitHub Actions/GitLab CI |
| Output Tuning | Configure Debugbar/JSON outputs for teams. | Frontend/Backend | Debugbar setup |
| Monitoring | Track false positives/negatives for 2 weeks. | TPM/Backend | Alert logs |
#laravel-performance).Debugbar per request).if: github.event_name == 'pull_request' to avoid running in prod pipelines.>100 queries/minute).| Failure Mode | Impact | Mitigation |
|---|---|---|
| False Positives | Devs ignore alerts for real N+1s. | Start with threshold=1, refine whitelists. |
| Output Spam | Too many alerts/log entries. | Use Log output in CI, Alert locally. |
| Laravel Version Mismatch | Package breaks on upgrade. | Test with new Laravel versions early. |
| CI Flakiness | N+1 checks fail intermittently. | Cache results or use sampling. |
| Debugbar Conflicts | Output clashes with other Debugbar collectors. | Use unique collector names. |
How can I help you explore Laravel packages today?