Skip to content

Commit

Permalink
fix double code for string value
Browse files Browse the repository at this point in the history
  • Loading branch information
PyaeSoneAungRgn committed Feb 8, 2023
1 parent df1618b commit d999365
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/ToRawSqlServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
});
}

Expand Down
2 changes: 1 addition & 1 deletion tests/ToRawSqlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)");
});

0 comments on commit d999365

Please sign in to comment.