Skip to content

Instantly share code, notes, and snippets.

@nasrulhazim
Created September 30, 2021 04:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nasrulhazim/7a2dfad8fcf28cbd1d94b4e76db3bbd0 to your computer and use it in GitHub Desktop.
Save nasrulhazim/7a2dfad8fcf28cbd1d94b4e76db3bbd0 to your computer and use it in GitHub Desktop.
A helper to Dump Query Builder SQL Statement with it's Bindings
<?php
use Illuminate\Database\Eloquent\Builder;
if (! function_exists('dumpSql')) {
function dumpSql(Builder $builder)
{
return array_reduce($builder->getBindings(), function ($sql, $binding) {
return preg_replace('/\?/', is_numeric($binding) ? $binding : "'".$binding."'", $sql, 1);
}, $builder->toSql());
}
}
// Reference: somewhere in Stackoverflow..haha
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment