Skip to content

Instantly share code, notes, and snippets.

@Ellrion
Last active February 29, 2020 12:38
Show Gist options
  • Save Ellrion/561fc48894a87b853917e0a5cec83181 to your computer and use it in GitHub Desktop.
Save Ellrion/561fc48894a87b853917e0a5cec83181 to your computer and use it in GitHub Desktop.
<?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