A little macro to get the SQL from a query builder without the annoying "?".
<?php | |
use Illuminate\Database\Eloquent\Builder; | |
Builder::macro('toSqlWithBindings', function () { | |
$bindings = array_map( | |
fn ($value) => is_numeric($value) ? $value : "'{$value}'", | |
$this->getBindings() | |
); | |
return Str::replaceArray('?', $bindings, $this->toSql()); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment