]> BookStack Code Mirror - bookstack/blob - app/Actions/Comment.php
Fixed occurances of altered titles in search results
[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\Factories\HasFactory;
8 use Illuminate\Database\Eloquent\Relations\MorphTo;
9
10 /**
11  * @property int      $id
12  * @property string   $text
13  * @property string   $html
14  * @property int|null $parent_id
15  * @property int      $local_id
16  */
17 class Comment extends Model
18 {
19     use HasFactory;
20     use HasCreatorAndUpdater;
21
22     protected $fillable = ['text', 'parent_id'];
23     protected $appends = ['created', 'updated'];
24
25     /**
26      * Get the entity that this comment belongs to.
27      */
28     public function entity(): MorphTo
29     {
30         return $this->morphTo('entity');
31     }
32
33     /**
34      * Check if a comment has been updated since creation.
35      */
36     public function isUpdated(): bool
37     {
38         return $this->updated_at->timestamp > $this->created_at->timestamp;
39     }
40
41     /**
42      * Get created date as a relative diff.
43      *
44      * @return mixed
45      */
46     public function getCreatedAttribute()
47     {
48         return $this->created_at->diffForHumans();
49     }
50
51     /**
52      * Get updated date as a relative diff.
53      *
54      * @return mixed
55      */
56     public function getUpdatedAttribute()
57     {
58         return $this->updated_at->diffForHumans();
59     }
60 }
Morty Proxy This is a proxified and sanitized view of the page, visit original site.