File tree 1 file changed +12
-24
lines changed
1 file changed +12
-24
lines changed Original file line number Diff line number Diff line change @@ -7,15 +7,22 @@ class QueryBuilderMixin
7
7
/**
8
8
* Returns sql query with binding replaced!
9
9
*
10
- * @return string
10
+ * @param ?\Closure $callable
11
+ * @return
11
12
*/
12
13
public function getSql ()
13
14
{
14
- return function () {
15
- return QueryViewer::replaceBindings (
15
+ return function ($ callable = null ) {
16
+ $ sql = QueryViewer::replaceBindings (
16
17
$ this ->toSql (),
17
18
$ this ->getBindings ()
18
19
);
20
+
21
+ if (is_null ($ callable )) {
22
+ return $ sql ;
23
+ }
24
+
25
+ return $ callable ($ sql );
19
26
};
20
27
}
21
28
@@ -39,31 +46,12 @@ public function dumpSql()
39
46
* @param null|string $prefix
40
47
* @return
41
48
*/
42
- public function logSql ($ prefix = null )
49
+ public function logSql ()
43
50
{
44
- return function ($ prefix ) {
51
+ return function ($ prefix = null ) {
45
52
logger ()->{config ('query-viewer.log_type ' )}($ prefix .' : ' .$ this ->getSql ());
46
53
47
54
return $ this ;
48
55
};
49
56
}
50
-
51
- /**
52
- * This method takes closure and gives sql as its parameter.
53
- * Can be used for custom logging.
54
- *
55
- * Example:
56
- * Model::select(a, b, c)->getSqlFunc(function($sql){ logger()->error($sql); })->get();
57
- *
58
- * @param null|\Closure $func
59
- * @return
60
- */
61
- public function getSqlFunc ($ func = null )
62
- {
63
- return function ($ func ) {
64
- $ func ($ this ->getSql ());
65
-
66
- return $ this ;
67
- };
68
- }
69
57
}
You can’t perform that action at this time.
0 commit comments