Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Laravel Query Detector

Laravel Query Detector Laravel Package

beyondcode/laravel-query-detector

Detect N+1 query issues in Laravel during development. Monitors database queries in real time and alerts you when repeated queries suggest missing eager loading, helping you optimize performance and reduce unnecessary database calls.

View on GitHub
Deep Wiki
Context7

Laravel N+1 Query Detector

Frequently asked questions about Laravel Query Detector
How do I install BeyondCode’s Laravel Query Detector without breaking my existing Laravel app?
Run `composer require beyondcode/laravel-query-detector --dev`—the package auto-registers and works out-of-the-box in debug mode. No manual configuration is needed for basic usage, and it won’t interfere with production unless explicitly enabled.
Does this package work with Laravel Lumen or Octane?
Yes, it supports Lumen (requires manual provider registration in `bootstrap/app.php`) and Octane. For Lumen, check the docs for a one-line composer script to auto-register the service provider. Octane compatibility is maintained via Laravel’s event system.
Can I whitelist specific relations to avoid false N+1 alerts?
Absolutely. Use the `except` config array in `config/querydetector.php` to exclude relations like `User::class => [Post::class]`. For easier management, the package suggests adding a CLI command (`php artisan query:whitelist`) to auto-detect and suggest whitelisted relations.
Will this slow down my production environment if accidentally enabled?
No, it’s disabled by default in production. Even if enabled, the overhead is minimal (~1–2ms per request). Always use environment checks (e.g., `app()->isLocal()`) or feature flags to gate its behavior in live environments.
How do I integrate alerts with Slack or Sentry?
Leverage the `QueryDetected` event to create custom listeners. For example, dispatch a Slack notification or log to Sentry by listening to the event in an event service provider. The package’s event-driven design makes third-party integrations straightforward.
Does this package work with Laravel 5.7 or older versions?
It supports Laravel 5.7 through 12.x. For legacy apps, ensure your `composer.json` constraints allow the package’s minimum version (5.7+). No additional steps are required beyond installation.
How can I see N+1 warnings in API responses without breaking client apps?
Use the JSON output format, but conditionally include it only in debug mode or via headers (e.g., `X-Query-Debug: true`). This prevents polluting production API responses while still surfacing issues during development.
What if Debugbar isn’t installed but I still want visual alerts?
The package supports alternative outputs like logging, console alerts, or Clockwork (if installed). Fall back to `Log` or `Alert` channels in `config/querydetector.php` if Debugbar isn’t available.
Can I auto-fix N+1 queries using this package?
Not directly, but you can trigger custom logic via the `QueryDetected` event. For example, use GitHub Actions to auto-commit eager-loading fixes when alerts are logged, or integrate with tools like Laravel Shift for automated refactoring.
What’s the best way to test this package in CI/CD pipelines?
Enable it in CI for debug environments (e.g., `APP_ENV=testing`) and fail builds if N+1 queries exceed your threshold. Use the `--env=testing` flag with `php artisan` commands to simulate debug mode, then parse logs or JSON outputs for violations.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
codraw/entity-migrator
codraw/doctrine-extra
codraw/aws-tool-kit
codraw/validator
codraw/workflow
codraw/open-api
codraw/cron-job
codraw/process
codraw/log
nexmo/api-specification
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony