Last active
November 12, 2024 12:14
-
-
Save lorisleiva/bdbb5aece08b674a7cb9511934b3e049 to your computer and use it in GitHub Desktop.
A little macro to get the SQL from a query builder without the annoying "?".
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 | |
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