From d9464d3e0b9f3cf1a1cfb53b4ca902159d72cfcc Mon Sep 17 00:00:00 2001 From: Tim Bornick Date: Wed, 6 Mar 2024 13:42:28 +0100 Subject: [PATCH] [Fix] Handle model custom timestamps (created_at, updated_at, deleted_at) --- src/Concerns/HasDrafts.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Concerns/HasDrafts.php b/src/Concerns/HasDrafts.php index 70c5ab4..a40d8e9 100644 --- a/src/Concerns/HasDrafts.php +++ b/src/Concerns/HasDrafts.php @@ -92,7 +92,7 @@ protected function newRevision(): void // This model has been set not to create a revision || $this->shouldCreateRevision() === false // The record is being soft deleted or restored - || $this->isDirty('deleted_at') + || $this->isDirty(method_exists($this, 'getDeletedAtColumn') ? $this->getDeletedAtColumn() : 'deleted_at') // A listener of the creatingRevision event returned false || $this->fireModelEvent('creatingRevision') === false ) { @@ -106,8 +106,8 @@ protected function newRevision(): void return; } - $revision->created_at = $this->created_at; - $revision->updated_at = $this->updated_at; + $revision->{$this->getCreatedAtColumn()} = $this->{$this->getCreatedAtColumn()}; + $revision->{$this->getUpdatedAtColumn()} = $this->{$this->getUpdatedAtColumn()}; $revision->is_current = false; $revision->is_published = false; @@ -337,7 +337,7 @@ public function pruneRevisions() { self::withoutEvents(function () { $revisionsToKeep = $this->revisions() - ->orderByDesc('updated_at') + ->orderByDesc($this->getUpdatedAtColumn()) ->onlyDrafts() ->withoutCurrent() ->take(config('drafts.revisions.keep'))