Skip to content

Instantly share code, notes, and snippets.

View azizramdan's full-sized avatar

Aziz Ramdan Kurniawan azizramdan

View GitHub Profile
private function getSql($query)
{
$bindings = $query->getBindings();
return preg_replace_callback('/\?/', function ($match) use (&$bindings, $query) {
return $query->getConnection()->getPdo()->quote(array_shift($bindings));
}, $query->toSql());
}
use Illuminate\Database\Events\QueryExecuted;
@azizramdan
azizramdan / web.php
Last active March 19, 2025 07:03
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