File tree Expand file tree Collapse file tree 1 file changed +12
-24
lines changed Expand file tree Collapse file tree 1 file changed +12
-24
lines changed Original file line number Diff line number Diff line change @@ -7,15 +7,22 @@ class QueryBuilderMixin
77 /**
88 * Returns sql query with binding replaced!
99 *
10- * @return string
10+ * @param ?\Closure $callable
11+ * @return
1112 */
1213 public function getSql ()
1314 {
14- return function () {
15- return QueryViewer::replaceBindings (
15+ return function ($ callable = null ) {
16+ $ sql = QueryViewer::replaceBindings (
1617 $ this ->toSql (),
1718 $ this ->getBindings ()
1819 );
20+
21+ if (is_null ($ callable )) {
22+ return $ sql ;
23+ }
24+
25+ return $ callable ($ sql );
1926 };
2027 }
2128
@@ -39,31 +46,12 @@ public function dumpSql()
3946 * @param null|string $prefix
4047 * @return
4148 */
42- public function logSql ($ prefix = null )
49+ public function logSql ()
4350 {
44- return function ($ prefix ) {
51+ return function ($ prefix = null ) {
4552 logger ()->{config ('query-viewer.log_type ' )}($ prefix .' : ' .$ this ->getSql ());
4653
4754 return $ this ;
4855 };
4956 }
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- }
6957}
You can’t perform that action at this time.
0 commit comments