Skip to content

Instantly share code, notes, and snippets.

@akrez
Last active November 22, 2025 10:34
Show Gist options
  • Select an option

  • Save akrez/b1d7900b7b5b4265e733f02bd4ed2d99 to your computer and use it in GitHub Desktop.

Select an option

Save akrez/b1d7900b7b5b4265e733f02bd4ed2d99 to your computer and use it in GitHub Desktop.
log all queries
<?php
public function boot()
{
\Illuminate\Database\Eloquent\Builder::macro('toRawQuery', function () {
/** @var Builder $this */
$sql = $this->toSql();
$bindings = $this->getBindings();
$bindings = array_map(function ($binding) {
if (is_null($binding)) {
return 'NULL';
}
return is_numeric($binding) ? $binding : "'" . addslashes($binding) . "'";
}, $bindings);
return vsprintf(str_replace('?', '%s', $sql), $bindings);
});
}
DB::listen(function (QueryExecuted $query) {
info("🔵\t".$query->toRawSql());
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment