Skip to content

Commit d02934b

Browse files
authored
[Fix] Handle model custom timestamps (created_at, updated_at, deleted_at) (#48)
1 parent b3b3435 commit d02934b

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

Diff for: src/Concerns/HasDrafts.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ protected function newRevision(): void
9292
// This model has been set not to create a revision
9393
|| $this->shouldCreateRevision() === false
9494
// The record is being soft deleted or restored
95-
|| $this->isDirty('deleted_at')
95+
|| $this->isDirty(method_exists($this, 'getDeletedAtColumn') ? $this->getDeletedAtColumn() : 'deleted_at')
9696
// A listener of the creatingRevision event returned false
9797
|| $this->fireModelEvent('creatingRevision') === false
9898
) {
@@ -106,8 +106,8 @@ protected function newRevision(): void
106106
return;
107107
}
108108

109-
$revision->created_at = $this->created_at;
110-
$revision->updated_at = $this->updated_at;
109+
$revision->{$this->getCreatedAtColumn()} = $this->{$this->getCreatedAtColumn()};
110+
$revision->{$this->getUpdatedAtColumn()} = $this->{$this->getUpdatedAtColumn()};
111111
$revision->is_current = false;
112112
$revision->is_published = false;
113113

@@ -337,7 +337,7 @@ public function pruneRevisions()
337337
{
338338
self::withoutEvents(function () {
339339
$revisionsToKeep = $this->revisions()
340-
->orderByDesc('updated_at')
340+
->orderByDesc($this->getUpdatedAtColumn())
341341
->onlyDrafts()
342342
->withoutCurrent()
343343
->take(config('drafts.revisions.keep'))

0 commit comments

Comments
 (0)