Skip to content

Instantly share code, notes, and snippets.

@mbpcoder
Created June 14, 2018 12:24
Show Gist options
  • Save mbpcoder/220948c949ae9c18d9632753a847884d to your computer and use it in GitHub Desktop.
Save mbpcoder/220948c949ae9c18d9632753a847884d to your computer and use it in GitHub Desktop.
Laravel get SQL with binding by Query object
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