PHPackages                             queryguard/laravel - 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. [Logging &amp; Monitoring](/categories/logging)
4. /
5. queryguard/laravel

ActiveLibrary[Logging &amp; Monitoring](/categories/logging)

queryguard/laravel
==================

Production query health for Laravel — continuous SQL monitoring, deploy regression tracking, AI-powered fix recipes.

v0.1.2(today)02↑2900%MITPHPPHP ^8.2

Since Jun 13Pushed todayCompare

[ Source](https://github.com/wilfridterry/query-guard)[ Packagist](https://packagist.org/packages/queryguard/laravel)[ Docs](https://queryguard.dev)[ RSS](/packages/queryguard-laravel/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (7)Versions (4)Used By (0)

QueryGuard
==========

[](#queryguard)

Production query health monitoring for Laravel. Catch slow queries, N+1 bugs, and missing indexes — with AI-powered fix suggestions and ready-to-run migrations.

Features
--------

[](#features)

- **Slow Query Detection** — track queries exceeding your threshold (default 500ms)
- **N+1 Detection** — spot repeated query patterns within a single request
- **Missing Index Detection** — identify unindexed columns in slow queries
- **AI-Powered Analysis** — diagnosis and migration code via Claude or OpenAI (optional, BYO key)
- **Zero Production Overhead** — configurable sampling, ignore lists, buffered processing
- **Privacy First** — only normalized SQL templates leave your server, never values

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

[](#installation)

```
composer require queryguard/laravel
php artisan migrate
```

Publish config (optional):

```
php artisan vendor:publish --provider="QueryGuard\QueryGuardServiceProvider" --tag="config"
```

Configuration
-------------

[](#configuration)

```
// config/queryguard.php
return [
    'enabled'               => env('QUERYGUARD_ENABLED', true),
    'sample_rate'           => env('QUERYGUARD_SAMPLE_RATE', 1.0),
    'slow_threshold_ms'     => 500,
    'n_plus_one_threshold'  => 10,
    'ignore' => [
        'tables' => ['telescope_*', 'pulse_*', 'jobs', 'sessions', 'cache'],
        'paths'  => ['horizon*', 'telescope*'],
    ],
    'storage' => [
        'retention_days' => 14,
    ],
    'explain' => [
        'enabled'        => true,
        'on_demand_only' => true,
    ],
    'ai' => [
        'provider' => env('QUERYGUARD_AI', null),  // 'anthropic' | 'openai' | null
        'api_key'  => env('QUERYGUARD_AI_KEY'),
        'model'    => env('QUERYGUARD_AI_MODEL', 'claude-sonnet-4-6'),
    ],
];
```

Usage
-----

[](#usage)

### Report all issues

[](#report-all-issues)

```
php artisan queryguard:report
php artisan queryguard:report --type=slow
php artisan queryguard:report --type=n_plus_one
php artisan queryguard:report --type=missing_index
```

### AI analysis of a specific query

[](#ai-analysis-of-a-specific-query)

```
php artisan queryguard:analyze ab12cd34ef56
```

Requires `QUERYGUARD_AI_KEY` in `.env`. Returns diagnosis, root cause, suggested migration and Eloquent pattern.

### Generate and apply a fix

[](#generate-and-apply-a-fix)

```
php artisan queryguard:fix ab12cd34ef56
```

Generates a migration file. You review and run it yourself — QueryGuard never auto-applies migrations.

### Signal a deploy (Cloud, Phase 3)

[](#signal-a-deploy-cloud-phase-3)

```
php artisan queryguard:deploy --sha=abc123 --branch=main
```

How It Works
------------

[](#how-it-works)

### Fingerprinting

[](#fingerprinting)

Every SQL query is normalized into a template — all literals replaced with `?`, `IN` lists collapsed:

```
Raw:      SELECT * FROM orders WHERE user_id = 42 AND status IN (1, 2, 3)
Template: SELECT * FROM orders WHERE user_id = ? AND status IN (?)
Hash:     ab12cd34ef56...

```

Identical templates across requests share one fingerprint, enabling accurate aggregation and N+1 detection.

### Privacy guarantee

[](#privacy-guarantee)

The Fingerprinter strips all literals before any data is persisted or transmitted. A CI test asserts this invariant — it fails if any raw number or string value leaks into a template.

### Detectors

[](#detectors)

DetectorTrigger`SlowQueryDetector``max_ms >= slow_threshold_ms``NPlusOneDetector`same fingerprint repeats `>= n_plus_one_threshold` times per request`MissingIndexDetector`slow query WHERE/JOIN columns not covered by any indexRequirements
------------

[](#requirements)

- PHP 8.2+
- Laravel 10, 11, or 12
- MySQL 5.7+ or PostgreSQL 12+ or SQLite (testing)

Testing
-------

[](#testing)

```
composer test
```

Roadmap
-------

[](#roadmap)

- v0.1 — Slow / N+1 / missing index detection, AI fix suggestions, migration generator
- v0.2 — Cloud transport (batched metrics ingestion)
- Cloud — Deploy-linked regression detection, Filament dashboard, Stripe billing

License
-------

[](#license)

MIT

###  Health Score

38

—

LowBetter than 83% of packages

Maintenance100

Actively maintained with recent releases

Popularity3

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity38

Early-stage or recently created project

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 ~0 days

Total

3

Last Release

0d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/32565967?v=4)[Zalevschi Stanislav](/maintainers/wilfridterry)[@wilfridterry](https://github.com/wilfridterry)

---

Tags

laravelmonitoringperformancequeryn-plus-oneslow query

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/queryguard-laravel/health.svg)

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

###  Alternatives

[spatie/laravel-health

Monitor the health of a Laravel application

87311.3M150](/packages/spatie-laravel-health)[psalm/plugin-laravel

Psalm plugin for Laravel

3325.1M337](/packages/psalm-plugin-laravel)[itpathsolutions/dbstan

Database Standardization and Analysis Tool for Laravel

442.1k](/packages/itpathsolutions-dbstan)

PHPackages © 2026

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