File tree Expand file tree Collapse file tree 2 files changed +23
-8
lines changed Expand file tree Collapse file tree 2 files changed +23
-8
lines changed Original file line number Diff line number Diff line change 2
2
3
3
namespace PyaeSoneAung \ToRawSql ;
4
4
5
+ use DateTimeInterface ;
5
6
use Illuminate \Database \Eloquent \Builder ;
6
7
use Illuminate \Support \Str ;
7
8
use Spatie \LaravelPackageTools \Package ;
@@ -12,13 +13,17 @@ class ToRawSqlServiceProvider extends PackageServiceProvider
12
13
public function boot (): void
13
14
{
14
15
Builder::macro ('toRawSql ' , function (): string {
15
- /** @var \Illuminate\Database\Eloquent\Builder $this */
16
- $ bindings = [];
17
- foreach ($ this ->getBindings () as $ value ) {
18
- if (is_string ($ value )) {
19
- $ bindings [] = "' {$ value }' " ;
20
- } else {
21
- $ bindings [] = $ value ;
16
+ /**
17
+ * @var \Illuminate\Database\Eloquent\Builder $this
18
+ */
19
+ $ bindings = $ this ->getBindings ();
20
+ foreach ($ bindings as $ key => $ value ) {
21
+ if ($ value instanceof DateTimeInterface) {
22
+ $ bindings [$ key ] = "' {$ value ->format ('Y-m-d H:i:s ' )}' " ;
23
+ } elseif (is_bool ($ value )) {
24
+ $ bindings [$ key ] = (int ) $ value ;
25
+ } elseif (is_string ($ value )) {
26
+ $ bindings [$ key ] = "' {$ value }' " ;
22
27
}
23
28
}
24
29
Original file line number Diff line number Diff line change 8
8
$ query ->where ('name ' , 'Abigail ' )
9
9
->where ('votes ' , '> ' , 50 );
10
10
})
11
+ ->where (
12
+ 'created_at ' ,
13
+ now ()
14
+ ->setYear (2023 )
15
+ ->setMonth (02 )
16
+ ->setDay (10 )
17
+ ->setHour (13 )
18
+ ->setMinute (22 )
19
+ ->setSecond (38 )
20
+ )
11
21
->toRawSql ()
12
- )->toBe ("select * from `users` where `votes` > 100 or (`name` = 'Abigail' and `votes` > 50) " );
22
+ )->toBe ("select * from `users` where `votes` > 100 or (`name` = 'Abigail' and `votes` > 50) and `created_at` = '2023-02-10 13:22:38' " );
13
23
});
You can’t perform that action at this time.
0 commit comments