Last active
February 29, 2020 12:38
-
-
Save Ellrion/561fc48894a87b853917e0a5cec83181 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
if (! function_exists('dqd')) { | |
/** | |
* Dump info about query in builder and end the script. | |
* | |
* @param $query | |
* @param bool $short | |
*/ | |
function dqd($query, $short = false) | |
{ | |
if ($query instanceof \Illuminate\Database\Eloquent\Builder) { | |
$query = $query->getQuery(); | |
} | |
$sql = $query->toSql(); | |
$bindings = array_map(function ($binding) { | |
return is_int($binding) || is_float($binding) ? $binding : "'{$binding}'"; | |
}, $query->getBindings()); | |
$raw = vsprintf(str_replace(['%', '?'], ['%%', '%s'], $sql), $bindings); | |
$bindings = $query->getRawBindings(); | |
if ($short) { | |
dd($raw); | |
} | |
dd(compact('sql', 'bindings', 'raw')); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment