PHPackages                             guanguans/laravel-dump-sql - 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. guanguans/laravel-dump-sql

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

guanguans/laravel-dump-sql
==========================

laravel 中轻松容易的输出完整的 SQL 语句。 - Easy output of complete SQL statements for laravel framework.

2.5.0(2y ago)3837.9k—3.6%5MITPHPPHP &gt;=7.3CI passing

Since Jul 12Pushed 1w ago1 watchersCompare

[ Source](https://github.com/guanguans/laravel-dump-sql)[ Packagist](https://packagist.org/packages/guanguans/laravel-dump-sql)[ Fund](https://www.guanguans.cn/images/wechat.jpeg)[ Patreon](https://www.patreon.com/guanguans)[ RSS](/packages/guanguans-laravel-dump-sql/feed)WikiDiscussions master Synced today

READMEChangelog (8)Dependencies (17)Versions (35)Used By (0)

laravel-dump-sql
================

[](#laravel-dump-sql)

[![](docs/dump-server.gif)](docs/dump-server.gif)

[![tests](https://github.com/guanguans/laravel-dump-sql/workflows/tests/badge.svg)](https://github.com/guanguans/laravel-dump-sql/actions)[![check & fix styling](https://github.com/guanguans/laravel-dump-sql/actions/workflows/php-cs-fixer.yml/badge.svg)](https://github.com/guanguans/laravel-dump-sql/actions)[![codecov](https://camo.githubusercontent.com/d30bf6bf3c6b974e15bef04ba3648298b5c7810523b86ce634c4bccd5e54f7e4/68747470733a2f2f636f6465636f762e696f2f67682f6775616e6775616e732f6c61726176656c2d64756d702d73716c2f67726170682f62616467652e7376673f746f6b656e3d4b4a544947534b443044)](https://codecov.io/gh/guanguans/laravel-dump-sql)[![Latest Stable Version](https://camo.githubusercontent.com/b1343f9d71eef6af3bd7e400d46e3b81f4ec49c62508d830ba7406cce463de82/68747470733a2f2f706f7365722e707567782e6f72672f6775616e6775616e732f6c61726176656c2d64756d702d73716c2f76)](//packagist.org/packages/guanguans/laravel-dump-sql)[![Total Downloads](https://camo.githubusercontent.com/15f7a381e440411abdde1e578475b7c8b3a9cd82857e863377e9abee48c53d99/68747470733a2f2f706f7365722e707567782e6f72672f6775616e6775616e732f6c61726176656c2d64756d702d73716c2f646f776e6c6f616473)](//packagist.org/packages/guanguans/laravel-dump-sql)[![License](https://camo.githubusercontent.com/48876e067f1719a03e52f3ddcd9930ac84fde5c23df35b4ecb01aa3fa1f6fcdc/68747470733a2f2f706f7365722e707567782e6f72672f6775616e6775616e732f6c61726176656c2d64756d702d73716c2f6c6963656e7365)](//packagist.org/packages/guanguans/laravel-dump-sql)

> Assist laravel application to obtain complete sql statement. - 辅助 laravel 应用获取完整的 sql 语句。

> The sql statement obtained by the query construction method in laravel is not bound to the conditional parameters, similar to `select * from users where id= ?`. This expansion pack can help you get a complete sql statement. - laravel 中查询构造方法得到的 sql 语句没有绑定条件参数，类似于`select * from users where id= ?`。这个扩展包可辅助你获取完整的 sql 语句。

功能
--

[](#功能)

- 添加获取 sql 语句的查询构建便捷方法(`toRawSql`、`dumpSql`、`ddSql`、`logListenedSql`、`dumpListenedSql`、`ddListenedSql`)
- 添加监控 sql 语句的服务命令

环境要求
----

[](#环境要求)

- laravel || lumen &gt;= 6.10

安装
--

[](#安装)

```
$ composer require guanguans/laravel-dump-sql -v
```

### lumen 中配置(laravel 中请忽略)

[](#lumen-中配置laravel-中请忽略)

将下面代码添加到 `bootstrap/app.php` 文件中的 `Register Service Providers` 部分

```
$app->register(\Guanguans\LaravelDumpSql\ServiceProvider::class);
```

使用
--

[](#使用)

### 监控 sql 语句的服务的使用

[](#监控-sql-语句的服务的使用)

```
$ php artisan server:dump-sql
```

[![](docs/dump-server.png)](docs/dump-server.png)

### 获取 sql 语句的查询构建便捷方法的使用

[](#获取-sql-语句的查询构建便捷方法的使用)

安装配置完毕后数据库查询构造方法会新增以下几个方法：

- toRawSql() - 获取完整的 sql
- dumpSql() - 打印完整的 sql
- ddSql() - 打印完整的 sql 并且退出
- logListenedSql() - 记录被监听到的 sql
- dumpListenedSql() - 打印被监听到的 sql
- ddListenedSql() - 打印被监听到的 sql 并且退出

#### toRawSql() - 获取完整的 sql

[](#torawsql---获取完整的-sql)

```
$sql = User::query()->where('id', 1)->toRawSql();
dd($sql);
```

```
"select * from `xb_users` where `id` = 1"
```

#### dumpSql() - 打印完整的 sql

[](#dumpsql---打印完整的-sql)

```
User::query()->where('id', 1)->dumpSql();
User::query()->where('id', 2)->dumpSql();
```

```
"select * from `xb_users` where `id` = 1"
"select * from `xb_users` where `id` = 2"
```

#### ddSql() - 打印完整的 sql 并且退出

[](#ddsql---打印完整的-sql-并且退出)

```
User::query()->where('id', 1)->ddSql();
User::query()->where('id', 2)->ddSql();
```

```
"select * from `xb_users` where `id` = 1"
```

#### logListenedSql() - 记录被监听到的 sql

[](#loglistenedsql---记录被监听到的-sql)

```
User::query()->where('id', 1)->logListenedSql()->first();
User::query()->where('id', 2)->first();
```

```
# 日志中
[Laravel] [39.97ms] select * from `xb_users` where `id` = '1' limit 1 | GET: /
[Laravel] [39.93ms] select * from `xb_users` where `id` = '2' limit 1 | GET: /
```

#### dumpListenedSql() - 打印被监听到的 sql

[](#dumplistenedsql---打印被监听到的-sql)

```
User::query()->where('id', 1)->dumpListenedSql()->first();
User::query()->where('id', 2)->first();
```

```
[Laravel] [39.97ms] select * from `xb_users` where `id` = '1' limit 1 | GET: /
[Laravel] [39.93ms] select * from `xb_users` where `id` = '2' limit 1 | GET: /
```

#### ddListenedSql() - 打印被监听到的 sql 并且退出

[](#ddlistenedsql---打印被监听到的-sql-并且退出)

```
User::query()->where('id', 1)->ddListenedSql()->first();
User::query()->where('id', 2)->first();
```

```
[Laravel] [39.97ms] select * from `xb_users` where `id` = '1' limit 1 | GET: /
```

安全漏洞
----

[](#安全漏洞)

请查看[我们的安全政策](../../security/policy)了解如何报告安全漏洞。

贡献者
---

[](#贡献者)

- [guanguans](https://github.com/guanguans)
- [所有贡献者](../../contributors)

协议
--

[](#协议)

MIT 许可证（MIT）。有关更多信息，请参见[协议文件](LICENSE)。

###  Health Score

49

—

FairBetter than 94% of packages

Maintenance64

Regular maintenance activity

Popularity40

Moderate usage in the ecosystem

Community14

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 72% 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 ~44 days

Recently: every ~178 days

Total

31

Last Release

841d ago

Major Versions

v1.2.2 → v2.0.02021-11-03

PHP version history (3 changes)v1.1.1PHP &gt;=7.1

v2.0.0PHP &gt;=7.2

2.4.0PHP &gt;=7.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/a49e4a0625bdf47c4e2924dcf07a053538d0c3a1e9287e8d6bfe68ed4017aa6f?d=identicon)[guanguans](/maintainers/guanguans)

---

Top Contributors

[![guanguans](https://avatars.githubusercontent.com/u/22309277?v=4)](https://github.com/guanguans "guanguans (157 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (41 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (15 commits)")[![ImgBotApp](https://avatars.githubusercontent.com/u/31427850?v=4)](https://github.com/ImgBotApp "ImgBotApp (5 commits)")

---

Tags

dumplaravelmysqlsqllaraveldebugdumpmysqlsqldd

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm, Rector

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/guanguans-laravel-dump-sql/health.svg)

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

###  Alternatives

[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9762.4M131](/packages/roots-acorn)[laravel/cashier

Laravel Cashier provides an expressive, fluent interface to Stripe's subscription billing services.

2.6k29.9M146](/packages/laravel-cashier)[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[mike-bronner/laravel-model-caching

Automatic caching for Eloquent models.

2.4k90.5k1](/packages/mike-bronner-laravel-model-caching)[api-platform/laravel

API Platform support for Laravel

58171.4k14](/packages/api-platform-laravel)[masterix21/laravel-licensing

Laravel licensing package with polymorphic assignment to any model, activation keys, expirations/renewals, and seat control via LicenseUsage. Supports offline verification with public-key–signed tokens, a CLI to generate/rotate/revoke keys, and an extensible architecture via config and contracts.

1563.0k4](/packages/masterix21-laravel-licensing)

PHPackages © 2026

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