]> BookStack Code Mirror - bookstack/blob - app/Actions/Comment.php
Modernize third party services' logos
[bookstack] / app / Actions / Comment.php
1 <?php
2
3 namespace BookStack\Actions;
4
5 use BookStack\Model;
6 use BookStack\Traits\HasCreatorAndUpdater;
7 use Illuminate\Database\Eloquent\Relations\MorphTo;
8
9 /**
10  * @property int      $id
11  * @property string   $text
12  * @property string   $html
13  * @property int|null $parent_id
14  * @property int      $local_id
15  */
16 class Comment extends Model
17 {
18     use HasCreatorAndUpdater;
19
20     protected $fillable = ['text', 'parent_id'];
21     protected $appends = ['created', 'updated'];
22
23     /**
24      * Get the entity that this comment belongs to.
25      */
26     public function entity(): MorphTo
27     {
28         return $this->morphTo('entity');
29     }
30
31     /**
32      * Check if a comment has been updated since creation.
33      */
34     public function isUpdated(): bool
35     {
36         return $this->updated_at->timestamp > $this->created_at->timestamp;
37     }
38
39     /**
40      * Get created date as a relative diff.
41      *
42      * @return mixed
43      */
44     public function getCreatedAttribute()
45     {
46         return $this->created_at->diffForHumans();
47     }
48
49     /**
50      * Get updated date as a relative diff.
51      *
52      * @return mixed
53      */
54     public function getUpdatedAttribute()
55     {
56         return $this->updated_at->diffForHumans();
57     }
58 }