Skip to content

Instantly share code, notes, and snippets.

@321zeno
Created February 27, 2017 11:16
Show Gist options
  • Save 321zeno/c02806ae1708b71249e3a73a2017acab to your computer and use it in GitHub Desktop.
Save 321zeno/c02806ae1708b71249e3a73a2017acab to your computer and use it in GitHub Desktop.
Debugging a Laravel query
<?php
// $query would be a query builder object
$bindings = $query->getBindings();
foreach ($bindings as $i => $binding) {
if ($binding instanceof \DateTime) {
$bindings[$i] = $binding->format('\'Y-m-d H:i:s\'');
} elseif (is_string($binding)) {
$bindings[$i] = "'$binding'";
}
}
$query = str_replace(array('%', '?'), array('%%', '%s'), $query->toSql());
$query = vsprintf($query, $bindings);
dd($query);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment