@@ -74,35 +74,27 @@ protected function getQueryColumns(array $columns) : string
74
74
75
75
protected function getWhereClauses (array $ wheres = []) : string
76
76
{
77
- $ wheres = collect ($ wheres );
78
-
79
- if ($ wheres ->isEmpty ()) {
80
- $ wheres = collect ($ this ->query ->wheres );
81
- }
82
-
83
- return $ wheres ->reduce (function ($ carry , $ where ) {
84
- if (in_array ($ where ['type ' ], ['Exists ' , 'Nested ' , 'NotExists ' ])) {
85
- return '_ ' . strtolower ($ where ['type ' ]) . $ this ->getWhereClauses ($ where ['query ' ]->wheres );
86
- }
77
+ return $ this ->getWheres ($ wheres )
78
+ ->reduce (function ($ carry , $ where ) {
79
+ if (in_array ($ where ['type ' ], ['Exists ' , 'Nested ' , 'NotExists ' ])) {
80
+ return '_ ' . strtolower ($ where ['type ' ]) . $ this ->getWhereClauses ($ where ['query ' ]->wheres );
81
+ }
87
82
88
- if ($ where ['type ' ] === 'Column ' ) {
89
- return "_ {$ where ['boolean ' ]}_ {$ where ['first ' ]}_ {$ where ['operator ' ]}_ {$ where ['second ' ]}" ;
90
- }
83
+ if ($ where ['type ' ] === 'Column ' ) {
84
+ return "_ {$ where ['boolean ' ]}_ {$ where ['first ' ]}_ {$ where ['operator ' ]}_ {$ where ['second ' ]}" ;
85
+ }
91
86
92
- if ($ where ['type ' ] === 'raw ' ) {
93
- return "_ {$ where ['boolean ' ]}_ " . str_slug ($ where ['sql ' ]);
94
- }
87
+ if ($ where ['type ' ] === 'raw ' ) {
88
+ return "_ {$ where ['boolean ' ]}_ " . str_slug ($ where ['sql ' ]);
89
+ }
95
90
96
- $ value = array_get ($ where , 'value ' );
97
- $ value .= in_array ($ where ['type ' ], ['In ' , 'Null ' , 'NotNull ' ])
98
- ? strtolower ($ where ['type ' ])
99
- : '' ;
100
- $ value .= is_array (array_get ($ where , 'values ' ))
101
- ? '_ ' . implode ('_ ' , $ where ['values ' ])
102
- : '' ;
91
+ $ value = array_get ($ where , 'value ' );
92
+ $ value .= $ this ->getTypeClause ($ where );
93
+ $ value .= $ this ->getValuesClause ($ where );
103
94
104
- return "{$ carry }- {$ where ['column ' ]}_ {$ value }" ;
105
- }) ?: '' ;
95
+ return "{$ carry }- {$ where ['column ' ]}_ {$ value }" ;
96
+ })
97
+ . '' ;
106
98
}
107
99
108
100
protected function getWithModels () : string
@@ -246,4 +238,29 @@ public function sum($column)
246
238
return parent ::sum ($ column );
247
239
});
248
240
}
241
+
242
+ protected function getTypeClause ($ where )
243
+ {
244
+ return in_array ($ where ['type ' ], ['In ' , 'Null ' , 'NotNull ' ])
245
+ ? strtolower ($ where ['type ' ])
246
+ : '' ;
247
+ }
248
+
249
+ protected function getValuesClause ($ where )
250
+ {
251
+ return is_array (array_get ($ where , 'values ' ))
252
+ ? '_ ' . implode ('_ ' , $ where ['values ' ])
253
+ : '' ;
254
+ }
255
+
256
+ protected function getWheres (array $ wheres ) : Collection
257
+ {
258
+ $ wheres = collect ($ wheres );
259
+
260
+ if ($ wheres ->isEmpty ()) {
261
+ $ wheres = collect ($ this ->query ->wheres );
262
+ }
263
+
264
+ return $ wheres ;
265
+ }
249
266
}
0 commit comments