Skip to content

Commit

Permalink
[Fix] Handle model custom timestamps (created_at, updated_at, deleted…
Browse files Browse the repository at this point in the history
…_at) (#48)
  • Loading branch information
kinkaz authored Mar 6, 2024
1 parent b3b3435 commit d02934b
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/Concerns/HasDrafts.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
) {
Expand All @@ -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;

Expand Down Expand Up @@ -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'))
Expand Down

0 comments on commit d02934b

Please sign in to comment.