]> BookStack Code Mirror - bookstack/commitdiff
#47 Adds two attributes updated and created to display time to user.
authorAbijeet <redacted>
Thu, 25 May 2017 02:33:27 +0000 (08:03 +0530)
committerAbijeet <redacted>
Thu, 25 May 2017 02:33:27 +0000 (08:03 +0530)
app/Comment.php

index e7df3201514a503d35a2f87186a93dd713631c79..34abdcf29d7a98a9d583c9bd6af7043db9c2556d 100644 (file)
@@ -6,7 +6,7 @@ use Illuminate\Support\Facades\DB;
 class Comment extends Ownable
 {
     protected $fillable = ['text', 'html', 'parent_id'];
-
+    protected $appends = ['created', 'updated'];
     /**
      * Get the entity that this comment belongs to
      * @return \Illuminate\Database\Eloquent\Relations\MorphTo
@@ -53,4 +53,23 @@ class Comment extends Ownable
         $query->orderBy('created_at');
         return $query;
     }
+
+    public function getCreatedAttribute() {
+        $created = [
+            'day_time_str' => $this->created_at->toDayDateTimeString(),
+            'diff' => $this->created_at->diffForHumans()
+        ];
+        return $created;
+    }
+
+    public function getUpdatedAttribute() {
+        if (empty($this->updated_at)) {
+            return null;
+        }
+        $updated = [
+            'day_time_str' => $this->updated_at->toDayDateTimeString(),
+            'diff' => $this->updated_at->diffForHumans()
+        ];
+        return $updated;
+    }
 }
Morty Proxy This is a proxified and sanitized view of the page, visit original site.