laravel 记录 sql

// 开启记录
\Illuminate\Support\Facades\DB::connection()->enableQueryLog();

// 打印记录
$bindings = \Illuminate\Support\Facades\DB::getQueryLog();
$data = [];
foreach ($bindings as $k => $b) {
    $bi = $b['bindings'];
    $bi = array_map(function ($a) {
        return '\'' . $a . '\'';
    }, $bi);
    $sql = str_replace('?', '%s', $b['query']);
    $sql2 = sprintf($sql, ...$bi);
    $data[$k] = $sql2;
}
dd($data);

此处评论已关闭