Skip to content

Commit 32d10a5

Browse files
committed
readme updated
1 parent f96ddd8 commit 32d10a5

File tree

1 file changed

+24
-16
lines changed

1 file changed

+24
-16
lines changed

README.md

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,20 @@
77

88
## Package description
99

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)
1111

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` = ?
1517
```
1618

1719
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'
2024
```
2125

2226
## Requirement
@@ -44,7 +48,7 @@ After installing this package you can use these methods on eloquent and database
4448

4549
- `getSql`
4650
* 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.
4852
* Returns string or closure result.
4953

5054
- `dumpSql`
@@ -53,7 +57,7 @@ After installing this package you can use these methods on eloquent and database
5357

5458
- `logSql`
5559
* 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.
5761
* Log type can be set in config file (default is "info").
5862
* Returns builder.
5963

@@ -70,17 +74,19 @@ User::select('name')->where('id', 5)->getSql();
7074
User::select('name')
7175
->where('id', 5)
7276
->dumpSql()
77+
// PRINTS: select `name` from `users` where `id` = 5
7378
->logSql('LOG_PREFIX_HERE') // logs sql to log file. (LOG_PREFIX_HERE : select `name` from `users` where `id` = 5)
7479
->where('name', '!=', 'john')
7580
->dumpSql()
81+
// PRINTS: select `name` from `users` where `id` = 5 and `name` != 'john'
7682
->where('surname', '!=', 'doe')
7783
->where('email', 'LIKE', '%example%')
7884
->getSql(function(string $sql) {
7985
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%'
8490
```
8591

8692
#### Database Builder
@@ -92,17 +98,19 @@ User::select('name')
9298
\DB::table('users')
9399
->where('id', 5)
94100
->dumpSql()
101+
// PRINTS: select `name` from `users` where `id` = 5
95102
->logSql('LOG_PREFIX_HERE') // logs sql to log file. (LOG_PREFIX_HERE : select `name` from `users` where `id` = 5)
96103
->where('name', '!=', 'john')
97104
->dumpSql()
105+
// PRINTS: select `name` from `users` where `id` = 5 and `name` != 'john'
98106
->where('surname', '!=', 'doe')
99107
->where('email', 'LIKE', '%example%')
100108
->getSql(function(string $sql) {
101109
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%'
106114
```
107115

108116
#### Replace bindings for all queries

0 commit comments

Comments
 (0)