Created
May 22, 2018 03:35
-
-
Save HavenShen/1bd9af978f86ffc6b3cbcf9948bdc61b to your computer and use it in GitHub Desktop.
打印 Laravel 框架 sql 带参数 sql 语句。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
|-------------------------------------------------------------------------- | |
| 打印 Laravel 框架 sql 带参数 sql | |
|-------------------------------------------------------------------------- | |
| | |
| 打印 Laravel 框架 sql 带参数 sql 语句。 | |
| | |
*/ | |
\DB::listen(function($query) { | |
$sql = $query->sql; | |
foreach ($query->bindings as $replace){ | |
$value = is_numeric($replace) ? $replace : "'".$replace."'"; | |
$sql = preg_replace('/\?/', $value, $sql, 1); | |
} | |
dd($sql); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment