Skip to content

Commit d999365

Browse files
fix double code for string value
1 parent df1618b commit d999365

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/ToRawSqlServiceProvider.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,15 @@ public function boot(): void
1313
{
1414
Builder::macro('toRawSql', function (): string {
1515
/** @var \Illuminate\Database\Eloquent\Builder $this */
16-
return Str::replaceArray('?', $this->getBindings(), $this->toSql());
16+
$bindings = [];
17+
foreach ($this->getBindings() as $value) {
18+
if (is_string($value)) {
19+
$bindings[] = "'{$value}'";
20+
} else {
21+
$bindings[] = $value;
22+
}
23+
}
24+
return Str::replaceArray('?', $bindings, $this->toSql());
1725
});
1826
}
1927

tests/ToRawSqlTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@
99
->where('votes', '>', 50);
1010
})
1111
->toRawSql()
12-
)->toBe('select * from `users` where `votes` > 100 or (`name` = Abigail and `votes` > 50)');
12+
)->toBe("select * from `users` where `votes` > 100 or (`name` = 'Abigail' and `votes` > 50)");
1313
});

0 commit comments

Comments
 (0)