Created
February 27, 2017 11:16
-
-
Save 321zeno/c02806ae1708b71249e3a73a2017acab to your computer and use it in GitHub Desktop.
Debugging a Laravel query
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 | |
// $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