44use Illuminate \Database \Eloquent \Model ;
55use Illuminate \Database \Query \Builder ;
66use Illuminate \Support \Collection ;
7+ use Illuminate \Database \Query \Expression ;
78
89class CacheKey
910{
@@ -40,7 +41,7 @@ public function make(
4041 $ key .= $ this ->getOffsetClause ();
4142 $ key .= $ this ->getLimitClause ();
4243 $ key .= $ keyDifferentiator ;
43-
44+ // dump($key);
4445 return $ key ;
4546 }
4647
@@ -120,8 +121,6 @@ protected function getValuesClause(array $where = null) : string
120121 $ values = $ this ->getValuesFromWhere ($ where );
121122 $ values = $ this ->getValuesFromBindings ($ where , $ values );
122123
123-
124-
125124 return "_ " . $ values ;
126125 }
127126
@@ -140,15 +139,16 @@ protected function getValuesFromWhere(array $where) : string
140139 }
141140
142141 if (is_array (array_get ($ where , "values " ))) {
143- return implode ("_ " , $ where ["values " ]);
142+ return implode ("_ " , collect ( $ where ["values " ])-> flatten ()-> toArray () );
144143 }
145144
146145 return array_get ($ where , "value " , "" );
147146 }
148147
149148 protected function getValuesFromBindings (array $ where , string $ values ) : string
150149 {
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 ) {
152152 $ values = $ this ->query ->bindings ["where " ][$ this ->currentBinding ];
153153 $ this ->currentBinding ++;
154154
@@ -169,8 +169,7 @@ protected function getWhereClauses(array $wheres = []) : string
169169 $ value .= $ this ->getNestedClauses ($ where );
170170 $ value .= $ this ->getColumnClauses ($ where );
171171 $ value .= $ this ->getRawClauses ($ where );
172- $ value .= $ this ->getInClauses ($ where );
173- $ value .= $ this ->getNotInClauses ($ where );
172+ $ value .= $ this ->getInAndNotInClauses ($ where );
174173 $ value .= $ this ->getOtherClauses ($ where , $ carry );
175174
176175 return $ value ;
@@ -207,23 +206,40 @@ protected function getInClauses(array $where) : string
207206 return "- {$ where ["column " ]}_in {$ values }" ;
208207 }
209208
210- protected function getNotInClauses (array $ where ) : string
209+ protected function getInAndNotInClauses (array $ where ) : string
211210 {
212- if (! in_array ($ where ["type " ], ["NotIn " ])) {
211+ if (! in_array ($ where ["type " ], ["In " , " NotIn " ])) {
213212 return "" ;
214213 }
215214
215+ $ type = strtolower ($ where ["type " ]);
216+ $ subquery = $ this ->getValuesFromWhere ($ where );
217+ $ values = collect ($ this ->query ->bindings ["where " ][$ this ->currentBinding ]);
216218 $ this ->currentBinding ++;
217- $ values = $ this ->recursiveImplode ($ where ["values " ], "_ " );
219+ $ subquery = collect (vsprintf (str_replace ("? " , "%s " , $ subquery ), $ values ->toArray ()));
220+ $ values = $ this ->recursiveImplode ($ subquery ->toArray (), "_ " );
218221
219- return "- {$ where ["column " ]}_not_in {$ values }" ;
222+ return "- {$ where ["column " ]}_ { $ type } {$ values }" ;
220223 }
221224
222225 protected function recursiveImplode (array $ items , string $ glue = ", " ) : string
223226 {
224227 $ result = "" ;
225228
226229 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+
227243 if (is_array ($ value )) {
228244 $ result .= $ this ->recursiveImplode ($ value , $ glue );
229245
0 commit comments