7
7
8
8
## Package description
9
9
10
- This package adds custom sql methods to eloquent and database query builder.
10
+ This package adds custom methods to eloquent and database query builder for getting sql query. (question marks replaced with values)
11
11
12
- Laravel's ` toSql() ` method gives you sql query without bindings replaced.
13
- ``` sql
14
- select ` name` from ` users` where ` id` = ? and ` name` = ?
12
+ Laravel's ` toSql() ` method gives you sql query without bindings replaced. (see question marks below)
13
+ ``` php
14
+ \DB::table('users')->select('name')->where('id', 5)->toSql();
15
+
16
+ // select `name` from `users` where `id` = ? and `name` = ?
15
17
```
16
18
17
19
With this package you have ` getSql() ` method. Which gives you same result with bindings replaced.
18
- ``` sql
19
- select ` name` from ` users` where ` id` = 5 and ` name` = ' laravel'
20
+ ``` php
21
+ \DB::table('users')->select('name')->where('id', 5)->getSql();
22
+
23
+ // select `name` from `users` where `id` = 5 and `name` = 'laravel'
20
24
```
21
25
22
26
## Requirement
@@ -44,7 +48,7 @@ After installing this package you can use these methods on eloquent and database
44
48
45
49
- ` getSql `
46
50
* This method returns sql query.
47
- * Optionally takes closure and calls closure with sql parameter .
51
+ * Optionally takes closure as parameter and calls closure with sql string .
48
52
* Returns string or closure result.
49
53
50
54
- ` dumpSql `
@@ -53,7 +57,7 @@ After installing this package you can use these methods on eloquent and database
53
57
54
58
- ` logSql `
55
59
* This method logs sql query.
56
- * Optionally takes prefix string. Which prepends to sql string.
60
+ * Optionally takes prefix string parameter . Which prepends to sql string.
57
61
* Log type can be set in config file (default is "info").
58
62
* Returns builder.
59
63
@@ -70,17 +74,19 @@ User::select('name')->where('id', 5)->getSql();
70
74
User::select('name')
71
75
->where('id', 5)
72
76
->dumpSql()
77
+ // PRINTS: select `name` from `users` where `id` = 5
73
78
->logSql('LOG_PREFIX_HERE') // logs sql to log file. (LOG_PREFIX_HERE : select `name` from `users` where `id` = 5)
74
79
->where('name', '!=', 'john')
75
80
->dumpSql()
81
+ // PRINTS: select `name` from `users` where `id` = 5 and `name` != 'john'
76
82
->where('surname', '!=', 'doe')
77
83
->where('email', 'LIKE', '%example%')
78
84
->getSql(function(string $sql) {
79
85
echo $sql;
80
- });
81
- // select `name` from `users` where `id` = 5
82
- // select `name` from `users` where `id` = 5 and `name` != 'john'
83
- // select `name` from `users` where `id` = 5 and `name` != 'john' and `surname` != 'doe' and `email` LIKE '%example%'
86
+ // select `name` from `users` where `id` = 5 and `name` != 'john' and `surname` != 'doe' and `email` LIKE '%example%'
87
+ })
88
+ ->getSql();
89
+ // PRINTS: select `name` from `users` where `id` = 5 and `name` != 'john' and `surname` != 'doe' and `email` LIKE '%example%'
84
90
```
85
91
86
92
#### Database Builder
@@ -92,17 +98,19 @@ User::select('name')
92
98
\DB::table('users')
93
99
->where('id', 5)
94
100
->dumpSql()
101
+ // PRINTS: select `name` from `users` where `id` = 5
95
102
->logSql('LOG_PREFIX_HERE') // logs sql to log file. (LOG_PREFIX_HERE : select `name` from `users` where `id` = 5)
96
103
->where('name', '!=', 'john')
97
104
->dumpSql()
105
+ // PRINTS: select `name` from `users` where `id` = 5 and `name` != 'john'
98
106
->where('surname', '!=', 'doe')
99
107
->where('email', 'LIKE', '%example%')
100
108
->getSql(function(string $sql) {
101
109
echo $sql;
102
- });
103
- // select `name` from `users` where `id` = 5
104
- // select `name` from `users` where `id` = 5 and `name` != 'john'
105
- // select `name` from `users` where `id` = 5 and `name` != 'john' and `surname` != 'doe' and `email` LIKE '%example%'
110
+ // select `name` from `users` where `id` = 5 and `name` != 'john' and `surname` != 'doe' and `email` LIKE '%example%'
111
+ })
112
+ ->getSql();
113
+ // PRINTS: select `name` from `users` where `id` = 5 and `name` != 'john' and `surname` != 'doe' and `email` LIKE '%example%'
106
114
```
107
115
108
116
#### Replace bindings for all queries
0 commit comments