PHPackages                             haru0/eloquent-sql-dumper - 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. haru0/eloquent-sql-dumper

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

haru0/eloquent-sql-dumper
=========================

Eloquent SQL dumper for Laravel

2.0.0(7y ago)216MITPHP

Since Feb 16Pushed 7y agoCompare

[ Source](https://github.com/Haru0/eloquent-sql-dumper)[ Packagist](https://packagist.org/packages/haru0/eloquent-sql-dumper)[ RSS](/packages/haru0-eloquent-sql-dumper/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (2)Versions (5)Used By (0)

[![CircleCI](https://camo.githubusercontent.com/c831b2156253842c5f0ee086d6daad8072816b36d9b814e90aaaaa134e5cb08b/68747470733a2f2f636972636c6563692e636f6d2f67682f48617275302f656c6f7175656e742d73716c2d64756d7065722e7376673f7374796c653d737667)](https://circleci.com/gh/Haru0/eloquent-sql-dumper)[![SymfonyInsight](https://camo.githubusercontent.com/9f3af6519e235ae95a966e933404409086e469c1d7b693b5b0cc070bf7cdb125/68747470733a2f2f696e73696768742e73796d666f6e792e636f6d2f70726f6a656374732f34333566656536652d366338332d346663302d613439652d3561366236666665663261362f6d696e692e737667)](https://insight.symfony.com/projects/435fee6e-6c83-4fc0-a49e-5a6b6ffef2a6)

Eloquent SQL dumper
-------------------

[](#eloquent-sql-dumper)

This **Laravel package** introduces simple service for **dumping** SQL with binded values.

This repository originated from [my personal blog](http://haracewiat.pl/2019/02/16/dump-eloquent-sql/), and aims to briefly explain advantages of Laravel's `Illuminate\Support\Traits\Macroable`.

Features
--------

[](#features)

Delivered `Haru0\EloquentSqlDumper\ServiceProvider` registers a `dump` macro on `Illuminate\Database\Query\Builder` which then could be then used for **logging** and **debugging**.

Although, you will be fine, I strongly discourage you from using this library on production for logging purposes. I believe it's not the proper way for this, and you should seek for dedicated logging solution.

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

[](#installation)

```
composer require --dev haru0/eloquent-sql-dumper
```

This package supports **package-discovery** and can be used straight away after adding to the Composer's dependencies.

If your project disables package-discovery feature, it is necessary to manually register `Haru0\EloquentSqlDumper\ServiceProvider`. This can be done by adding this line below, inside `config/app.php` file.

```
/*
 * Package Service Providers...
 */
Haru0\EloquentSqlDumper\ServiceProvider::class,
```

No configuration options available.

Usage
-----

[](#usage)

`Haru0\EloquentSqlDumper\Services\DumperService`, once registered, can be basically used anywhere. It is also easily **overrideable** and **extensible**.

Example `routes/web.php` file:

```
use Illuminate\Database\Query\Builder;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Route;

Route::get('/', function () {
    $query = DB::query()
        ->from('users')
        ->where('active', true)
        ->where(function (Builder $builder) {
            $builder
                ->orWhere('email', 'like', '%gmail.com')
                ->orWhere('email', 'like', '%example.com');
        })
        ->orderByDesc('id')
        ->limit(10);

    dd($query->dump());
});
```

`Tinker` version, for **REPL** lovers:

```
Psy Shell v0.9.9 (PHP 7.3.2-3+ubuntu18.04.1+deb.sury.org+1 — cli) by Justin Hileman
>>> DB::query() \
...     ->from('users') \
...     ->where('active', true) \
...     ->where(function ($builder) { \
...         $builder \
...             ->orWhere('email', 'like', '%gmail.com') \
...             ->orWhere('email', 'like', '%example.com'); \
...     }) \
...     ->orderByDesc('id') \
...     ->limit(10) \
...     ->dump()
=> "select * from `users` where `active` = 1 and (`email` like '%gmail.com' or `email` like '%example.com') order by `id` desc limit 10"
```

Overriding and extending
------------------------

[](#overriding-and-extending)

If you need to adjust or override `Haru0\EloquentSqlDumper\Services\DumperService` functionality, you're welcome to either **bind implementation to the contract**, or **register listener** to the two events dispatched by the service.

Depending on your needs, one of the ways of customizing `dump` macro, is to write your own `DumperService` and bind it to the `Haru0\EloquentSqlDumper\Contracts\DumperContract`.

```
use App\Services\MyDumper;
use Haru0\EloquentSqlDumper\Contracts\DumperContract;

$this->app->bind(DumperContract::class, MyDumper::class);
```

Other way of customizing `dump` macro is to register a [listener](https://laravel.com/docs/5.7/events#defining-listeners) or [subscriber](https://laravel.com/docs/5.7/events#event-subscribers) to the `Haru0\EloquentSqlDumper\Events\AfterDumpEvent` and `Haru0\EloquentSqlDumper\Events\BeforeDumpEvent` events.

Finally, you can modify macro name (in case it collides with existing one). To do so, adjust configuration option or put `ELOQUENT_SQL_DUMPER_MACRO` environment variable into your `.env` file.

```
ELOQUENT_SQL_DUMPER_MACRO=foo_bar_baz
```

> You can change that environment by overriding configuration file. Do do so, you need to publish package configuration file `php artisan vendor:publish --provider=Haru0\EloquentSqlDumper\ServiceProvider`.

Then, use it the same way `dump` was shown in the [Usage](#Usage) chapter.

> Macro name is **always** casted to [Camel case](https://en.wikipedia.org/wiki/Camel_case). In this example above, your macro will be executed by `$query->fooBarBaz`.

Contribute
----------

[](#contribute)

Any contribution is welcome. Fork this repository and create a pull request. Please remember to provide brief description.

[Here you can find all contributors](https://github.com/Haru0/eloquent-sql-dumper/graphs/contributors).

License
-------

[](#license)

MIT

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity63

Established project with proven stability

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

Total

3

Last Release

2624d ago

Major Versions

1.0.1 → 2.0.02019-03-03

### Community

Maintainers

![](https://www.gravatar.com/avatar/04006e68c242bee91263868ad9c2d9109b9101ca79a855754424fcd5ba20c219?d=identicon)[Haru0](/maintainers/Haru0)

---

Top Contributors

[![mharacewiat](https://avatars.githubusercontent.com/u/5583430?v=4)](https://github.com/mharacewiat "mharacewiat (24 commits)")

---

Tags

bindingsdebugdebuggingeloquentlaravellogloggingmacropackagesqlloglaravelloggingdebugpackagedebuggingsqleloquentmacrobindings

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/haru0-eloquent-sql-dumper/health.svg)

```
[![Health](https://phpackages.com/badges/haru0-eloquent-sql-dumper/health.svg)](https://phpackages.com/packages/haru0-eloquent-sql-dumper)
```

###  Alternatives

[owen-it/laravel-auditing

Audit changes of your Eloquent models in Laravel

3.4k33.0M95](/packages/owen-it-laravel-auditing)[danielme85/laravel-log-to-db

Custom Laravel Log channel handler that can store log events to SQL or MongoDB databases. Uses Laravel native logging functionality.

135934.5k1](/packages/danielme85-laravel-log-to-db)[altek/accountant

The auditing &amp; accountability package for Laravel's Eloquent ORM.

92954.3k4](/packages/altek-accountant)[betapeak/laravel-auditing-filesystem

A filesystem driver for the owen-it/laravel-auditing package. Allows storage of the audits in CSV files, across all registered Laravel disks.

166.5k](/packages/betapeak-laravel-auditing-filesystem)

PHPackages © 2026

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