-
-
Save devig/7b8f78ded2cebe4434e585c0c94e196f 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