Created
June 14, 2018 12:24
-
-
Save mbpcoder/220948c949ae9c18d9632753a847884d to your computer and use it in GitHub Desktop.
Laravel get SQL with binding by Query object
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
function getSql($query) | |
{ | |
$sql = $query->toSql(); | |
foreach ($query->getBindings() as $binding) { | |
$value = is_numeric($binding) ? $binding : "'" . $binding . "'"; | |
$sql = preg_replace('/\?/', $value, $sql, 1); | |
} | |
return $sql; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment