diff --git a/src/CacheKey.php b/src/CacheKey.php index 057582f..81f17f6 100644 --- a/src/CacheKey.php +++ b/src/CacheKey.php @@ -11,6 +11,7 @@ use Illuminate\Support\Str; use Ramsey\Uuid\Uuid; use UnitEnum; +use DateTime; class CacheKey { @@ -99,7 +100,12 @@ protected function getColumnClauses(array $where) : string protected function getCurrentBinding(string $type, $bindingFallback = null) { - return data_get($this->query->bindings, "{$type}.{$this->currentBinding}", $bindingFallback); + $binding = data_get($this->query->bindings, "{$type}.{$this->currentBinding}", $bindingFallback); + if ($binding instanceof DateTime) { + return $binding->format("Y-m-d-H-i-s"); + } + + return $binding; } protected function getHavingClauses() @@ -321,10 +327,7 @@ protected function getValuesClause(array $where = []) : string protected function getValuesFromWhere(array $where) : string { - if (array_key_exists("value", $where) - && is_object($where["value"]) - && get_class($where["value"]) === "DateTime" - ) { + if (array_key_exists("value", $where) && $where["value"] instanceof DateTime) { return $where["value"]->format("Y-m-d-H-i-s"); } @@ -442,12 +445,14 @@ protected function recursiveImplode(array $items, string $glue = ",") : string return $result; } - private function processEnum(BackedEnum|UnitEnum|Expression|string|null $value): ?string + private function processEnum(BackedEnum|UnitEnum|Expression|DateTime|string|null $value): ?string { if ($value instanceof BackedEnum) { return $value->value; } elseif ($value instanceof UnitEnum) { return $value->name; + } elseif ($value instanceof DateTime) { + return $value->format("Y-m-d-H-i-s"); } elseif ($value instanceof Expression) { return $this->expressionToString($value); }