PHPackages                             blissjaspis/laravel-query-detector - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. blissjaspis/laravel-query-detector

ActiveLibrary[Database &amp; ORM](/categories/database)

blissjaspis/laravel-query-detector
==================================

Laravel N+1 Query Detector

v2.1.0(1mo ago)411.3k↑150%MITPHPPHP ^8.2CI passing

Since May 1Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/blissjaspis/laravel-query-detector)[ Packagist](https://packagist.org/packages/blissjaspis/laravel-query-detector)[ Docs](https://github.com/blissjaspis/laravel-query-detector)[ RSS](/packages/blissjaspis-laravel-query-detector/feed)WikiDiscussions main Synced yesterday

READMEChangelog (5)Dependencies (15)Versions (6)Used By (0)

Laravel N+1 Query Detector
==========================

[](#laravel-n1-query-detector)

The Laravel N+1 query detector helps you improve application performance by spotting relation queries that should be eager loaded. It monitors queries in real time during development and notifies you when an N+1 pattern is detected.

[![Example alert](/asset/n+.png)](/asset/n+.png)

History
-------

[](#history)

This repository is a fork of [beyondcode/laravel-query-detector](https://github.com/beyondcode/laravel-query-detector). The original package was not updated for newer Laravel releases, so this fork keeps the tool compatible with current Laravel versions.

Compatibility
-------------

[](#compatibility)

### Version 2.x (current)

[](#version-2x-current)

Latest release: **2.1.0**. Compatible with **Laravel 12 and above** (PHP 8.2+).

### Version 1.x

[](#version-1x)

For **Laravel 11 and below**:

```
composer require blissjaspis/laravel-query-detector:^1.0 --dev
```

Installation
------------

[](#installation)

Install as a development dependency:

```
composer require blissjaspis/laravel-query-detector --dev
```

The service provider is registered automatically.

Publish configuration (optional):

```
php artisan vendor:publish --provider="BlissJaspis\QueryDetector\QueryDetectorServiceProvider"
```

Usage
-----

[](#usage)

When `APP_DEBUG=true` (and `QUERY_DETECTOR_ENABLED` is not set to `false`), detection runs automatically on HTTP requests. No extra setup is required.

### Configuration

[](#configuration)

KeyDefaultDescription`enabled``null``null` uses `config('app.debug')`. Set `false` to disable explicitly.`threshold``1`Minimum number of identical relation queries before reporting.`except``[]`Whitelist per parent model. Use relation names (e.g. `posts`) or related model classes.`excluded_paths``[]`Extra stack trace paths to ignore.`log_channel``daily`Log channel when using the Log output.`output``Alert`, `Log`Default output classes (see below).`route_output``[]`URI pattern → output classes (e.g. `api/*` → Json + Log).`route_names``[]`Route name pattern → output classes (e.g. `api.*`).`output_aliases`built-inShort names for `querydetector.output` route middleware.Environment variables:

- `QUERY_DETECTOR_ENABLED`
- `QUERY_DETECTOR_THRESHOLD`
- `QUERY_DETECTOR_LOG_CHANNEL`

### Output drivers

[](#output-drivers)

Configure `output` in `config/querydetector.php`:

ClassDescription`Outputs\Alert`Browser `alert()` on HTML responses`Outputs\Console`Browser `console.warn()` on HTML responses`Outputs\Log`Writes to a Laravel log channel`Outputs\Json`Appends `warning_queries` to JSON API responses`Outputs\Debugbar`Requires [`fruitcake/laravel-debugbar`](https://github.com/fruitcake/laravel-debugbar)`Outputs\Clockwork`Requires [`itsgoingd/clockwork`](https://github.com/itsgoingd/clockwork)Optional integrations are listed under `composer suggest`.

### Custom handling

[](#custom-handling)

Listen for `BlissJaspis\QueryDetector\Events\QueryDetected` to send notifications (Sentry, Slack, etc.):

```
use BlissJaspis\QueryDetector\Events\QueryDetected;

Event::listen(QueryDetected::class, function (QueryDetected $event) {
    foreach ($event->getQueries() as $query) {
        // $query['model'], $query['relation'], $query['relatedModel'], $query['count'], ...
    }
});
```

The event is dispatched once per HTTP request when issues are found.

### Scope and limitations

[](#scope-and-limitations)

- Detection runs on **HTTP requests** via global middleware. **No manual middleware registration** is required—the service provider registers it automatically.
- **Artisan commands, queue jobs, and schedulers** are not covered unless you wrap them manually in local dev (see [usage — Beyond HTTP](docs/usage.md#beyond-http-artisan-queues-and-jobs)).
- **Inertia / SPA**: prefer `Log` + `Json` output; `Alert` only helps on full HTML page loads ([usage — SPA and Inertia](docs/usage.md#spa-and-inertiajs)).
- Intended for **local/staging development** only; keep it as a `--dev` dependency.
- For Octane and other long-lived workers, the detector resets its state between requests but keeps a single `DB::listen` registration per worker process.

More detail: [docs/usage.md](docs/usage.md).

Package internals and class responsibilities: [docs/architecture.md](docs/architecture.md).

Development
-----------

[](#development)

```
composer install
composer test      # Run tests
composer lint      # Pint (dry-run) + PHPStan
composer format    # Apply Pint fixes
composer analyse   # PHPStan only
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

See [CHANGELOG](CHANGELOG.md).

Contributing
------------

[](#contributing)

See [CONTRIBUTING](CONTRIBUTING.md).

Security
--------

[](#security)

Report security issues to  instead of using the public issue tracker.

Credits
-------

[](#credits)

- [Bliss Jaspis](https://github.com/blissjaspis)
- [Marcel Pociot](https://github.com/mpociot)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). See [LICENSE](LICENSE.md).

###  Health Score

50

—

FairBetter than 95% of packages

Maintenance91

Actively maintained with recent releases

Popularity30

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~187 days

Total

5

Last Release

42d ago

Major Versions

1.1.1 → v2.0.02026-03-30

PHP version history (2 changes)1.0.0PHP ^8.1

v2.0.0PHP ^8.2

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/8768022?v=4)[jaspis](/maintainers/jaspis)[@jaspis](https://github.com/jaspis)

---

Top Contributors

[![blissjaspis](https://avatars.githubusercontent.com/u/19877298?v=4)](https://github.com/blissjaspis "blissjaspis (16 commits)")

---

Tags

laravel-query-detectorblissjaspis

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/blissjaspis-laravel-query-detector/health.svg)

```
[![Health](https://phpackages.com/badges/blissjaspis-laravel-query-detector/health.svg)](https://phpackages.com/packages/blissjaspis-laravel-query-detector)
```

###  Alternatives

[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k8.4M96](/packages/mongodb-laravel-mongodb)[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[yajra/laravel-oci8

Oracle DB driver for Laravel via OCI8

8793.2M25](/packages/yajra-laravel-oci8)[kirschbaum-development/eloquent-power-joins

The Laravel magic applied to joins.

1.6k32.6M46](/packages/kirschbaum-development-eloquent-power-joins)[glushkovds/phpclickhouse-laravel

Adapter of the most popular library https://github.com/smi2/phpClickHouse to Laravel

2051.5M2](/packages/glushkovds-phpclickhouse-laravel)[api-platform/laravel

API Platform support for Laravel

58171.4k14](/packages/api-platform-laravel)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
