2018-09-25 12:30:50 +01:00
|
|
|
<?php namespace BookStack\Actions;
|
|
|
|
|
2020-12-30 18:25:35 +00:00
|
|
|
use BookStack\Model;
|
|
|
|
use BookStack\Traits\HasCreatorAndUpdater;
|
|
|
|
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
2017-01-13 21:45:48 +05:30
|
|
|
|
2020-05-01 23:24:11 +01:00
|
|
|
/**
|
|
|
|
* @property string text
|
|
|
|
* @property string html
|
|
|
|
* @property int|null parent_id
|
|
|
|
* @property int local_id
|
|
|
|
*/
|
2020-12-30 18:25:35 +00:00
|
|
|
class Comment extends Model
|
2017-01-13 21:45:48 +05:30
|
|
|
{
|
2020-12-30 18:25:35 +00:00
|
|
|
use HasCreatorAndUpdater;
|
|
|
|
|
2020-05-01 23:24:11 +01:00
|
|
|
protected $fillable = ['text', 'parent_id'];
|
2017-09-03 16:37:51 +01:00
|
|
|
protected $appends = ['created', 'updated'];
|
|
|
|
|
2017-01-13 21:45:48 +05:30
|
|
|
/**
|
|
|
|
* Get the entity that this comment belongs to
|
|
|
|
*/
|
2020-12-30 18:25:35 +00:00
|
|
|
public function entity(): MorphTo
|
2017-01-13 21:45:48 +05:30
|
|
|
{
|
|
|
|
return $this->morphTo('entity');
|
|
|
|
}
|
2017-05-16 00:40:14 +05:30
|
|
|
|
2017-01-13 21:45:48 +05:30
|
|
|
/**
|
2017-09-03 16:37:51 +01:00
|
|
|
* Check if a comment has been updated since creation.
|
2017-01-13 21:45:48 +05:30
|
|
|
*/
|
2020-12-30 18:25:35 +00:00
|
|
|
public function isUpdated(): bool
|
2017-01-13 21:45:48 +05:30
|
|
|
{
|
2017-09-03 16:37:51 +01:00
|
|
|
return $this->updated_at->timestamp > $this->created_at->timestamp;
|
2017-01-13 21:45:48 +05:30
|
|
|
}
|
2017-05-16 00:40:14 +05:30
|
|
|
|
2017-01-13 21:45:48 +05:30
|
|
|
/**
|
2017-09-03 16:37:51 +01:00
|
|
|
* Get created date as a relative diff.
|
|
|
|
* @return mixed
|
2017-01-13 21:45:48 +05:30
|
|
|
*/
|
2017-09-03 16:37:51 +01:00
|
|
|
public function getCreatedAttribute()
|
2017-01-13 21:45:48 +05:30
|
|
|
{
|
2017-09-03 16:37:51 +01:00
|
|
|
return $this->created_at->diffForHumans();
|
2017-01-13 21:45:48 +05:30
|
|
|
}
|
2017-05-16 00:40:14 +05:30
|
|
|
|
2017-09-03 16:37:51 +01:00
|
|
|
/**
|
|
|
|
* Get updated date as a relative diff.
|
|
|
|
* @return mixed
|
2017-06-06 01:46:59 +05:30
|
|
|
*/
|
2017-09-03 16:37:51 +01:00
|
|
|
public function getUpdatedAttribute()
|
|
|
|
{
|
|
|
|
return $this->updated_at->diffForHumans();
|
2017-05-30 09:02:47 +05:30
|
|
|
}
|
2017-01-13 21:45:48 +05:30
|
|
|
}
|