4
4
use Illuminate \Database \Eloquent \Model ;
5
5
use Illuminate \Database \Query \Builder ;
6
6
use Illuminate \Support \Collection ;
7
+ use Illuminate \Database \Query \Expression ;
7
8
8
9
class CacheKey
9
10
{
@@ -40,7 +41,7 @@ public function make(
40
41
$ key .= $ this ->getOffsetClause ();
41
42
$ key .= $ this ->getLimitClause ();
42
43
$ key .= $ keyDifferentiator ;
43
-
44
+ // dump($key);
44
45
return $ key ;
45
46
}
46
47
@@ -120,8 +121,6 @@ protected function getValuesClause(array $where = null) : string
120
121
$ values = $ this ->getValuesFromWhere ($ where );
121
122
$ values = $ this ->getValuesFromBindings ($ where , $ values );
122
123
123
-
124
-
125
124
return "_ " . $ values ;
126
125
}
127
126
@@ -140,15 +139,16 @@ protected function getValuesFromWhere(array $where) : string
140
139
}
141
140
142
141
if (is_array (array_get ($ where , "values " ))) {
143
- return implode ("_ " , $ where ["values " ]);
142
+ return implode ("_ " , collect ( $ where ["values " ])-> flatten ()-> toArray () );
144
143
}
145
144
146
145
return array_get ($ where , "value " , "" );
147
146
}
148
147
149
148
protected function getValuesFromBindings (array $ where , string $ values ) : string
150
149
{
151
- if (! $ values && ($ this ->query ->bindings ["where " ][$ this ->currentBinding ] ?? false )) {
150
+ // if (! $values && ($this->query->bindings["where"][$this->currentBinding] ?? false)) {
151
+ if ($ this ->query ->bindings ["where " ][$ this ->currentBinding ] ?? false ) {
152
152
$ values = $ this ->query ->bindings ["where " ][$ this ->currentBinding ];
153
153
$ this ->currentBinding ++;
154
154
@@ -169,8 +169,7 @@ protected function getWhereClauses(array $wheres = []) : string
169
169
$ value .= $ this ->getNestedClauses ($ where );
170
170
$ value .= $ this ->getColumnClauses ($ where );
171
171
$ value .= $ this ->getRawClauses ($ where );
172
- $ value .= $ this ->getInClauses ($ where );
173
- $ value .= $ this ->getNotInClauses ($ where );
172
+ $ value .= $ this ->getInAndNotInClauses ($ where );
174
173
$ value .= $ this ->getOtherClauses ($ where , $ carry );
175
174
176
175
return $ value ;
@@ -207,23 +206,40 @@ protected function getInClauses(array $where) : string
207
206
return "- {$ where ["column " ]}_in {$ values }" ;
208
207
}
209
208
210
- protected function getNotInClauses (array $ where ) : string
209
+ protected function getInAndNotInClauses (array $ where ) : string
211
210
{
212
- if (! in_array ($ where ["type " ], ["NotIn " ])) {
211
+ if (! in_array ($ where ["type " ], ["In " , " NotIn " ])) {
213
212
return "" ;
214
213
}
215
214
215
+ $ type = strtolower ($ where ["type " ]);
216
+ $ subquery = $ this ->getValuesFromWhere ($ where );
217
+ $ values = collect ($ this ->query ->bindings ["where " ][$ this ->currentBinding ]);
216
218
$ this ->currentBinding ++;
217
- $ values = $ this ->recursiveImplode ($ where ["values " ], "_ " );
219
+ $ subquery = collect (vsprintf (str_replace ("? " , "%s " , $ subquery ), $ values ->toArray ()));
220
+ $ values = $ this ->recursiveImplode ($ subquery ->toArray (), "_ " );
218
221
219
- return "- {$ where ["column " ]}_not_in {$ values }" ;
222
+ return "- {$ where ["column " ]}_ { $ type } {$ values }" ;
220
223
}
221
224
222
225
protected function recursiveImplode (array $ items , string $ glue = ", " ) : string
223
226
{
224
227
$ result = "" ;
225
228
226
229
foreach ($ items as $ value ) {
230
+ if ($ value instanceof Expression) {
231
+ $ value = $ value ->getValue ();
232
+ }
233
+
234
+ if (is_string ($ value )) {
235
+ $ value = str_replace ('" ' , '' , $ value );
236
+ $ value = explode (" " , $ value );
237
+
238
+ if (count ($ value ) === 1 ) {
239
+ $ value = $ value [0 ];
240
+ }
241
+ }
242
+
227
243
if (is_array ($ value )) {
228
244
$ result .= $ this ->recursiveImplode ($ value , $ glue );
229
245
0 commit comments