Created
September 30, 2021 04:21
-
-
Save nasrulhazim/7a2dfad8fcf28cbd1d94b4e76db3bbd0 to your computer and use it in GitHub Desktop.
A helper to Dump Query Builder SQL Statement with it's Bindings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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