Looking to hire Laravel developers? Try LaraJobs

laravel-query-lens maintained by youngmayor

Description
A premium database query and performance developer dashboard for Laravel API endpoints.
Last update
2026/06/06 16:33 (dev-main)
License
Downloads
0

Comments
comments powered by Disqus

Laravel Query Lens

Latest Version on Packagist Total Downloads

Laravel Query Lens is a developer dashboard and CLI performance inspector for your Laravel database queries. It tracks query counts, duplicate SQL queries (N+1 detector), cache hit/miss ratio, memory footprint, and HTTP status codes per route. It also features a premium dark-mode Blade dashboard with a built-in SQL EXPLAIN query inspector.


Features

  • Zero-dependency dashboard: Pure Blade, Vanilla JS, and custom CSS (no Livewire or Flux required on the host application).
  • 🔍 N+1 and Duplicate Query Detection: Tracks duplicate execution counts to highlight redundant DB hits.
  • ⚙️ Performance Metrics: Measures execution duration, peak memory usage, and cache hit/miss ratio.
  • 📋 Built-in EXPLAIN Tool: Run EXPLAIN query analyzer directly from the dashboard modal.
  • 💻 CLI Console Report: Summarize endpoint performance metrics right from your terminal.
  • 🛠️ Configurable Storage: Choose between an isolated SQLite database or your host application's existing database.

Installation

Install the package via Composer:

composer require youngmayor/laravel-query-lens

Publish the package configuration:

php artisan vendor:publish --provider="Youngmayor\LaravelQueryLens\LaravelQueryLensServiceProvider" --tag="config"

This will create a config/laravel-query-lens.php configuration file in your host application.


Setup & Configuration

The package automatically registers its tracking middleware globally. You do not need to register it manually.

You can configure which routes are monitored by updating the paths array in config/laravel-query-lens.php. By default, only routes matching api/* are tracked:

'paths' => [
    'api/*', // Wildcards are supported
],

Configure Database Storage

By default, the package registers a dynamic SQLite connection named query_lens and stores logs in database/query_reporter.sqlite.

If you prefer to store metrics in your existing application database (e.g., MySQL or PostgreSQL), set the use_configured_database option to your connection name in config/laravel-query-lens.php:

'use_configured_database' => 'mysql', // Uses your default 'mysql' connection instead of SQLite

Usage

📊 Local Dashboard

The dashboard is accessible only in local and testing environments at /query-reporter (configurable via path in the config file).

🖥️ CLI Commands

Pre-load your monitored API endpoints into the database:

php artisan report:load-urls

Display endpoint stats in the terminal:

php artisan report:queries

Options:

  • --branch=: Filter records by Git branch.
  • --sort=: Sort table results by queries (default), runs, duplicates, or duration.

Testing

composer test

Credits

License

The MIT License (MIT). Please see License File for more information.