3 namespace BookStack\Activity\Models;
5 use BookStack\App\Model;
6 use BookStack\Users\Models\HasCreatorAndUpdater;
7 use Illuminate\Database\Eloquent\Factories\HasFactory;
8 use Illuminate\Database\Eloquent\Relations\MorphTo;
12 * @property string $text
13 * @property string $html
14 * @property int|null $parent_id
15 * @property int $local_id
16 * @property string $entity_type
17 * @property int $entity_id
19 class Comment extends Model implements Loggable
22 use HasCreatorAndUpdater;
24 protected $fillable = ['text', 'parent_id'];
25 protected $appends = ['created', 'updated'];
28 * Get the entity that this comment belongs to.
30 public function entity(): MorphTo
32 return $this->morphTo('entity');
36 * Check if a comment has been updated since creation.
38 public function isUpdated(): bool
40 return $this->updated_at->timestamp > $this->created_at->timestamp;
44 * Get created date as a relative diff.
48 public function getCreatedAttribute()
50 return $this->created_at->diffForHumans();
54 * Get updated date as a relative diff.
58 public function getUpdatedAttribute()
60 return $this->updated_at->diffForHumans();
63 public function logDescriptor(): string
65 return "Comment #{$this->local_id} (ID: {$this->id}) for {$this->entity_type} (ID: {$this->entity_id})";