guanguans/laravel-dump-sql -Easily output complete sql statements in laravel.
The SQL statement obtained by the query construction method in laravel has no conditional parameters, which is similar to
select * from users where id= ?
. This expansion pack can help you get a complete sql statement.
User::query()->where('id', 1)->dd(); // 自带方法 `dd` 的打印结果
User::query()->where('id', 1)->ddSql(); // 新增方法 `ddSql` 的打印结果
Environmental requirements
- laravel || lumen >= 5.5
Install
$ composer require guanguans/laravel-dump-sql -v
Configuration in lumen (please ignore in laravel)
Add the following code to the Register Service Providers
part of the bootstrap/app.php
$app->register(\Guanguans\LaravelDumpSql\ServiceProvider::class);
use
After installation and configuration, the database query construction method will add the following methods:
- toRawSql()-Get the complete sql
- dumpSql()-print the complete sql
- ddSql()-print the complete sql and exit
- logListenedSql()-Log the monitored sql
- dumpListenedSql()-print the monitored sql
- ddListenedSql()-print the monitored sql and exit
toRawSql()-Get the complete sql
$sql = User::query()->where('id', 1)->toRawSql();
dd($sql);
"select * from `xb_users` where `id` = 1"
dumpSql()-print the complete 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()-print the complete sql and exit
User::query()->where('id', 1)->ddSql();
User::query()->where('id', 2)->ddSql();
"select * from `xb_users` where `id` = 1"
logListenedSql()-Log the monitored 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()-print the monitored 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()-print the monitored sql and exit
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: /
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。