diff --git a/.gitignore b/.gitignore index 48b6166..c2d4570 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ composer.lock .phpunit.result.cache phpunit.xml +.idea diff --git a/src/CacheKey.php b/src/CacheKey.php index c4b985f..a8e2ee8 100644 --- a/src/CacheKey.php +++ b/src/CacheKey.php @@ -40,6 +40,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(); @@ -47,10 +48,31 @@ public function make( $key .= $this->getBindingsSlug(); $key .= $keyDifferentiator; $key .= $this->macroKey; -// dump($key); + return $key; } + 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}" : "";