diff --git a/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php b/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php index 4ef0f5314062..a88501e09280 100644 --- a/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php +++ b/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php @@ -1467,12 +1467,18 @@ protected function serializeDate(DateTimeInterface $date) * * @return array */ - public function getDates() + public function getDates(): array { - return $this->usesTimestamps() ? [ + $dateAttributes = array_filter( + array_keys($this->getCasts()), fn (string $key): bool => $this->isDateCastable($key) + ); + + $timestamps = $this->usesTimestamps() ? [ $this->getCreatedAtColumn(), $this->getUpdatedAtColumn(), ] : []; + + return array_unique([...$dateAttributes, ...$timestamps]); } /**