-<?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
{
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();
}
}