diff --git a/src/CacheKey.php b/src/CacheKey.php index a7ff568..057582f 100644 --- a/src/CacheKey.php +++ b/src/CacheKey.php @@ -51,6 +51,7 @@ public function make( $key .= $this->getIdColumn($idColumn ?: ""); $key .= $this->getQueryColumns($columns); $key .= $this->getWhereClauses(); + $key .= $this->getHavingClauses(); $key .= $this->getWithModels(); $key .= $this->getOrderByClauses(); $key .= $this->getOffsetClause(); @@ -58,7 +59,7 @@ public function make( $key .= $this->getBindingsSlug(); $key .= $keyDifferentiator; $key .= $this->macroKey; -// dump($key); + return $key; } @@ -101,6 +102,27 @@ protected function getCurrentBinding(string $type, $bindingFallback = null) return data_get($this->query->bindings, "{$type}.{$this->currentBinding}", $bindingFallback); } + protected function getHavingClauses() + { + return Collection::make($this->query->havings)->reduce(function ($carry, $having) { + $value = $carry; + $value .= $this->getHavingClause($having); + + return $value; + }); + } + + protected function getHavingClause(array $having): string + { + $return = '-having'; + + foreach ($having as $key => $value) { + $return .= '_' . $key . '_' . str_replace(' ', '_', $value); + } + + return $return; + } + protected function getIdColumn(string $idColumn) : string { return $idColumn ? "_{$idColumn}" : "";