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