Guanguans /laravel-dump-sql – Easily output complete SQL statements in Laravel.
SQL > select * from users where id=? SQL > select * from users where id=? . This extension helps you get complete SQL statements.
User::query()->where('id'.1)->dd(); // Print the result of the built-in method 'dd'
Copy the code
User::query()->where('id'.1)->ddSql(); // Add the print result of method 'ddSql'
Copy the code
Environmental requirements
- Laravel | | lumen > = 5.5
The installation
$ composer require guanguans/laravel-dump-sql -v
Copy the code
Configuration in LUMen (ignore in Laravel)
Add the following code to the Register Service Providers section of the bootstrap/app.php file
$app->register(\Guanguans\LaravelDumpSql\ServiceProvider::class);
Copy the code
use
After installation and configuration, the following methods will be added to the database query constructor:
- ToRawSql () – Get the full SQL
- DumpSql () – Prints the complete SQL
- DdSql () – Prints the complete SQL and exits
- LogListenedSql () – Records the SQL being listened on
- DumpListenedSql () – Prints the SQL listened on
- DdListenedSql () – Prints the monitored SQL and exits
ToRawSql () – Get the full SQL
$sql = User::query()->where('id'.1)->toRawSql();
dd($sql);
Copy the code
"select * from `xb_users` where `id` = 1"
Copy the code
DumpSql () – Prints the complete SQL
User::query()->where('id'.1)->dumpSql();
User::query()->where('id'.2)->dumpSql();
Copy the code
"select * from `xb_users` where `id` = 1"
"select * from `xb_users` where `id` = 2"
Copy the code
DdSql () – Prints the complete SQL and exits
User::query()->where('id'.1)->ddSql();
User::query()->where('id'.2)->ddSql();
Copy the code
"select * from `xb_users` where `id` = 1"
Copy the code
LogListenedSql () – Records the SQL being listened on
User::query()->where('id'.1)->logListenedSql()->first();
User::query()->where('id'.2)->first();
Copy the code
#In the log[Laravel] [39.97] ms select * from ` xb_users ` where ` ` id = '1' limit 1 | GET: / [Laravel] [39.93] ms select * from ` xb_users ` where ` ` id = '2' limit 1 | GET: /Copy the code
DumpListenedSql () – Prints the SQL listened on
User::query()->where('id'.1)->dumpListenedSql()->first();
User::query()->where('id'.2)->first();
Copy the code
[Laravel] [39.97] ms select * from ` xb_users ` where ` ` id = '1' limit 1 | GET: / [Laravel] [39.93] ms select * from ` xb_users ` where ` ` id = '2' limit 1 | GET: /Copy the code
DdListenedSql () – Prints the monitored SQL and exits
User::query()->where('id'.1)->ddListenedSql()->first();
User::query()->where('id'.2)->first();
Copy the code
[Laravel] [39.97] ms select * from ` xb_users ` where ` ` id = '1' limit 1 | GET: /Copy the code
Refer to the project
- Github.com/overtrue/la…