Skip to content

Updated timestamp not working #79

@tomhelmer

Description

@tomhelmer

The TracksLastModified trait has the function :

public function lastModified()
    {
        return $this->has('updated_at')
            ? Carbon::createFromTimestamp($this->get('updated_at'))
            : $this->fileLastModified();
    }

It expects the updated_at to be a timestamp, but the Eloquent driver set a Carbon object.

We use this patch :

diff --git a/src/Entries/Entry.php b/src/Entries/Entry.php
index 3344c2e..42e732c 100644
--- a/src/Entries/Entry.php
+++ b/src/Entries/Entry.php
@@ -25,7 +25,9 @@ class Entry extends FileEntry
             ->model($model);

         if (config('statamic.system.track_last_update')) {
-            $entry->set('updated_at', $model->updated_at ?? $model->created_at);
+            if ($updated_at = $model->updated_at ?? $model->created_at) {
+                $entry->set('updated_at', $updated_at->timestamp);
+            }
         }

         return $entry;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions