PHPackages                             mortenscheel/laravel-query-recorder - 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. mortenscheel/laravel-query-recorder

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

mortenscheel/laravel-query-recorder
===================================

A package to record and analyze database queries in Laravel applications.

3.0.0(1mo ago)17.8k↓40.5%MITPHPPHP ^8.4CI failing

Since Mar 13Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/mortenscheel/laravel-query-recorder)[ Packagist](https://packagist.org/packages/mortenscheel/laravel-query-recorder)[ RSS](/packages/mortenscheel-laravel-query-recorder/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (34)Versions (6)Used By (0)

 [![GitHub Workflow Status (master)](https://github.com/mortenscheel/laravel-query-recorder/actions/workflows/tests.yml/badge.svg)](https://github.com/mortenscheel/laravel-query-recorder/actions) [![Total Downloads](https://camo.githubusercontent.com/14daf402cc544cd84148058966534e3c708dbb168c6b025d4a2084d4aa0fc9f1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d6f7274656e73636865656c2f6c61726176656c2d71756572792d7265636f72646572)](https://packagist.org/packages/mortenscheel/laravel-query-recorder) [![Latest Version](https://camo.githubusercontent.com/da7132b6571bf6f0ee9c64bd1afb860923b72c0734aa50e26c701e88e491ba8f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d6f7274656e73636865656c2f6c61726176656c2d71756572792d7265636f72646572)](https://packagist.org/packages/mortenscheel/laravel-query-recorder) [![License](https://camo.githubusercontent.com/9855442ed306fb3855f9ad6a12e6a110359a46d64de085ad25d32d9a91dc4a3a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6d6f7274656e73636865656c2f6c61726176656c2d71756572792d7265636f72646572)](https://packagist.org/packages/mortenscheel/laravel-query-recorder)

Laravel Query Recorder
======================

[](#laravel-query-recorder)

A package to record and analyze database queries in Laravel applications.

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

[](#installation)

You can install the package via composer:

```
composer require mortenscheel/laravel-query-recorder --dev
```

Usage
-----

[](#usage)

This package comes with a couple of recorders.

### Recording all queries to CSV

[](#recording-all-queries-to-csv)

The package includes a CSV recorder that can write all queries to a CSV file. Example use in a controller:

```
use Scheel\QueryRecorder\Facades\QueryRecorder;
use Scheel\QueryRecorder\Processors\CsvProcessor;

class UserController extends Controller
{
    public function index()
    {
        // Create a CSV recorder with a file path
        $recorder = new CsvProcessor(storage_path('queries.csv'));

        // Start recording
        QueryRecorder::record($recorder);

        // Your controller logic with database queries
        $users = User::all();

        // The CSV will be written after the response has been sent
        // thanks to Laravel's defer() mechanism

        return view('users.index', compact('users'));
    }
}
```

The CSV file will include:

- Query time (ms)
- Origin (file and line number)
- SQL query (raw)

### Record duplicate queries to CSV

[](#record-duplicate-queries-to-csv)

```
use Scheel\QueryRecorder\Processors\DuplicateQueryCsvProcessor;

QueryRecorder::record(new DuplicateQueryCsvProcessor('/path/to/output.csv'));
```

This recorder will only show duplicate queries, grouped by both sql and origin. There will be one row per unique sql+origin, containing:

- Count
- Total time (ms)
- Origin
- SQL

### Custom Recorders

[](#custom-recorders)

You can create your own custom recorder by implementing the `RecordsQueries` interface:

```
use Scheel\QueryRecorder\RecordsQueries;
use Scheel\QueryRecorder\QueryCollection;

class CustomProcessor implements QueryCollectionProcessor
{
    public function process(QueryCollection $queries): void
    {
        // Custom implementation to record the queries collection
        // This will be called after the request is complete
    }
}
```

Usage example:

```
$recorder = new CustomProcessor();
QueryRecorder::record($recorder);

// Execute queries...
DB::table('users')->first();

// The recordQueries method will be called after the response
// has been sent, with all collected queries
```

### Query Origin Tracking

[](#query-origin-tracking)

One of the key features of this package is the ability to identify where in your code a query is being executed:

```
$query->origin->file     // The file path where the query was initiated
$query->origin->line     // The line number where the query was initiated
$query->origin->function // The function that initiated the query
$query->origin->class    // The class that initiated the query (if applicable)
$query->origin->type     // The type of call (static or instance method)

// Additional helper methods
$query->origin->isVendor()   // Check if the query originated from a vendor package
$query->origin->location()   // Get the file:line format
$query->origin->editorLink() // Get an editor link to the exact location
```

This is especially helpful for debugging and optimizing database queries in your application.

Listening for Queries
---------------------

[](#listening-for-queries)

This is similar to Laravel's `DB::listen()` except you receive a `RecordedQuery` with extra metadata.

```
use Scheel\QueryRecorder\Facades\QueryRecorder;

QueryRecorder::listen(function (RecordedQuery $query) {
    // Do something with the recorded query
    Log::debug('Query executed', ['origin' => $query->location(), 'sql' => $query->sql]);
});

// Execute database queries...
DB::table('users')->first();
```

Testing
-------

[](#testing)

```
composer test
```

Security
--------

[](#security)

If you discover any security related issues, please email the author instead of using the issue tracker.

Credits
-------

[](#credits)

- [Morten Scheel](https://github.com/mortenscheel)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

49

—

FairBetter than 95% of packages

Maintenance88

Actively maintained with recent releases

Popularity26

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity59

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

Total

5

Last Release

59d ago

Major Versions

0.2.0 → 1.0.02025-03-15

1.1.0 → 2.0.02025-03-28

2.0.0 → 3.0.02026-03-20

PHP version history (3 changes)0.2.0PHP ^8.3.0

1.0.0PHP ^8.2.0

3.0.0PHP ^8.4

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/6514342?v=4)[Morten Scheel](/maintainers/mortenscheel)[@mortenscheel](https://github.com/mortenscheel)

---

Top Contributors

[![mortenscheel](https://avatars.githubusercontent.com/u/6514342?v=4)](https://github.com/mortenscheel "mortenscheel (20 commits)")

---

Tags

phppackageSkeleton

###  Code Quality

TestsPest

Static AnalysisPHPStan, Rector

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/mortenscheel-laravel-query-recorder/health.svg)

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

###  Alternatives

[larastan/larastan

Larastan - Discover bugs in your code without running it. A phpstan/phpstan extension for Laravel

6.4k43.5M5.2k](/packages/larastan-larastan)[io238/laravel-iso-countries

Ready-to-use Laravel models and relations for country (ISO 3166), language (ISO 639-1), and currency (ISO 4217) information with multi-language support.

5462.3k](/packages/io238-laravel-iso-countries)[awssat/laravel-sync-migration

Laravel tool helps to sync migrations without refreshing the database

10923.2k](/packages/awssat-laravel-sync-migration)

PHPackages © 2026

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