diff --git a/src/ToRawSqlServiceProvider.php b/src/ToRawSqlServiceProvider.php index fe2ef9c..af024f1 100644 --- a/src/ToRawSqlServiceProvider.php +++ b/src/ToRawSqlServiceProvider.php @@ -13,7 +13,15 @@ public function boot(): void { Builder::macro('toRawSql', function (): string { /** @var \Illuminate\Database\Eloquent\Builder $this */ - return Str::replaceArray('?', $this->getBindings(), $this->toSql()); + $bindings = []; + foreach ($this->getBindings() as $value) { + if (is_string($value)) { + $bindings[] = "'{$value}'"; + } else { + $bindings[] = $value; + } + } + return Str::replaceArray('?', $bindings, $this->toSql()); }); } diff --git a/tests/ToRawSqlTest.php b/tests/ToRawSqlTest.php index 2334115..315d752 100644 --- a/tests/ToRawSqlTest.php +++ b/tests/ToRawSqlTest.php @@ -9,5 +9,5 @@ ->where('votes', '>', 50); }) ->toRawSql() - )->toBe('select * from `users` where `votes` > 100 or (`name` = Abigail and `votes` > 50)'); + )->toBe("select * from `users` where `votes` > 100 or (`name` = 'Abigail' and `votes` > 50)"); });