]> BookStack Code Mirror - bookstack/blobdiff - app/Comment.php
Actually fixed the BaseURL this time 🤦
[bookstack] / app / Comment.php
index 9ef892bdc09281b704555e3cc1748ac9f9dde754..2800ab21ad3d07a3fca32e28f045eccfad71b787 100644 (file)
@@ -1,11 +1,10 @@
-<?php
-
-namespace BookStack;
+<?php namespace BookStack;
 
 class Comment extends Ownable
 {
-    protected $fillable = ['text', 'html'];
-    
+    protected $fillable = ['text', 'html', 'parent_id'];
+    protected $appends = ['created', 'updated'];
+
     /**
      * Get the entity that this comment belongs to
      * @return \Illuminate\Database\Eloquent\Relations\MorphTo
@@ -14,22 +13,31 @@ class Comment extends Ownable
     {
         return $this->morphTo('entity');
     }
-    
+
     /**
-     * Get the page that this comment is in.
-     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
+     * Check if a comment has been updated since creation.
+     * @return bool
      */
-    public function page()
+    public function isUpdated()
     {
-        return $this->belongsTo(Page::class);
+        return $this->updated_at->timestamp > $this->created_at->timestamp;
     }
-    
+
+    /**
+     * Get created date as a relative diff.
+     * @return mixed
+     */
+    public function getCreatedAttribute()
+    {
+        return $this->created_at->diffForHumans();
+    }
+
     /**
-     * Get the owner of this comment.
-     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
+     * Get updated date as a relative diff.
+     * @return mixed
      */
-    public function user() 
+    public function getUpdatedAttribute()
     {
-        return $this->belongsTo(User::class);
+        return $this->updated_at->diffForHumans();
     }
 }