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 N+1 Query Detector?
Run `composer require beyondcode/laravel-query-detector --dev` to install it as a development dependency. The package auto-registers, so no additional steps are needed unless you want to customize its behavior via `php artisan vendor:publish`.
Does this package work with Laravel 12 and PHP 8.2+?
Yes, the package officially supports Laravel 5.7–12.x and PHP 8+. Check the [CHANGELOG](https://github.com/beyondcode/laravel-query-detector/blob/main/CHANGELOG.md) for version-specific updates, but it’s actively maintained for modern stacks.
Will this slow down my production environment?
No, the package is disabled in production by default (via `QUERY_DETECTOR_ENABLED`). Enable it only in development or staging to avoid runtime overhead. For high-traffic apps, consider sampling (e.g., monitoring 1% of requests).
How do I ignore specific queries or relationships?
Use the `except` configuration in `config/query-detector.php` to whitelist queries or relationships. For example, add `'except' => ['User::with('posts')->where(...)']` to skip dynamic or intentional N+1 patterns.
Can I integrate this with Sentry or Slack for alerts?
Yes, the package emits a `QueryDetected` event. Subscribe to it in an event listener to forward alerts to Sentry, Slack, or other tools. Example: `event(new QueryDetected($query, $count));` in your listener.
Does this work with Lumen or non-Eloquent queries?
The package supports Lumen via `LumenQueryDetectorServiceProvider` and focuses on Eloquent ORM/Query Builder. For raw PDO queries or non-Laravel stacks, you’d need a custom adapter, as it’s Laravel-centric.
How do I test if N+1 queries are fixed in my CI pipeline?
Mock the `QueryDetector` in unit tests to verify no N+1 queries exist in critical paths. For integration tests, enable the detector in your test environment and assert no alerts are triggered. Use `QueryDetector::assertNoQueries()` if available.
What’s the best way to visualize N+1 queries in my app?
Pair this with `barryvdh/laravel-debugbar` for a visual breakdown of queries. Alternatively, use the console output or log alerts to a file. For APIs, output JSON via a custom listener for frontend teams.
Are there alternatives to this package?
Yes, alternatives include `spatie/laravel-query-builder` (for query optimization) or `laravel-debugbar` (for general query logging). However, this package is specialized for real-time N+1 detection with minimal setup, making it ideal for Laravel devs.
How do I adjust the threshold for N+1 detection?
Set `QUERY_DETECTOR_THRESHOLD` in your `.env` (default: `1`). For example, `QUERY_DETECTOR_THRESHOLD=3` will alert only if a relationship is queried 3+ times. Start with `1` and refine based on your app’s traffic patterns.
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.
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope