Skip to content

Instantly share code, notes, and snippets.

@azizramdan
Last active March 19, 2025 07:03
Show Gist options
  • Save azizramdan/e0b07d7a9669f1633b9f4a3e7f8f96ef to your computer and use it in GitHub Desktop.
Save azizramdan/e0b07d7a9669f1633b9f4a3e7f8f96ef to your computer and use it in GitHub Desktop.
dump query
\DB::listen(function ($query) {
$sql = $query->sql;
$bindings = $query->bindings;
// Replace each ? with the corresponding binding
$index = 0;
$rawSql = preg_replace_callback('/\?/', function () use ($bindings, &$index) {
$value = $bindings[$index++];
// Format the value based on its type
if (is_string($value)) {
return "'" . addslashes($value) . "'";
} elseif (is_null($value)) {
return 'NULL';
} elseif (is_bool($value)) {
return $value ? '1' : '0';
}
return $value;
}, $sql);
dump($rawSql);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment