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