2017-09-03 17:37:51 +02:00
|
|
|
<?php namespace BookStack;
|
2017-01-13 17:15:48 +01:00
|
|
|
|
|
|
|
class Comment extends Ownable
|
|
|
|
{
|
2017-05-15 21:10:14 +02:00
|
|
|
protected $fillable = ['text', 'html', 'parent_id'];
|
2017-09-03 17:37:51 +02:00
|
|
|
protected $appends = ['created', 'updated'];
|
|
|
|
|
2017-01-13 17:15:48 +01:00
|
|
|
/**
|
|
|
|
* Get the entity that this comment belongs to
|
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\MorphTo
|
|
|
|
*/
|
|
|
|
public function entity()
|
|
|
|
{
|
|
|
|
return $this->morphTo('entity');
|
|
|
|
}
|
2017-05-15 21:10:14 +02:00
|
|
|
|
2017-01-13 17:15:48 +01:00
|
|
|
/**
|
2017-09-03 17:37:51 +02:00
|
|
|
* Check if a comment has been updated since creation.
|
|
|
|
* @return bool
|
2017-01-13 17:15:48 +01:00
|
|
|
*/
|
2017-09-03 17:37:51 +02:00
|
|
|
public function isUpdated()
|
2017-01-13 17:15:48 +01:00
|
|
|
{
|
2017-09-03 17:37:51 +02:00
|
|
|
return $this->updated_at->timestamp > $this->created_at->timestamp;
|
2017-01-13 17:15:48 +01:00
|
|
|
}
|
2017-05-15 21:10:14 +02:00
|
|
|
|
2017-01-13 17:15:48 +01:00
|
|
|
/**
|
2017-09-03 17:37:51 +02:00
|
|
|
* Get created date as a relative diff.
|
|
|
|
* @return mixed
|
2017-01-13 17:15:48 +01:00
|
|
|
*/
|
2017-09-03 17:37:51 +02:00
|
|
|
public function getCreatedAttribute()
|
2017-01-13 17:15:48 +01:00
|
|
|
{
|
2017-09-03 17:37:51 +02:00
|
|
|
return $this->created_at->diffForHumans();
|
2017-01-13 17:15:48 +01:00
|
|
|
}
|
2017-05-15 21:10:14 +02:00
|
|
|
|
2017-09-03 17:37:51 +02:00
|
|
|
/**
|
|
|
|
* Get updated date as a relative diff.
|
|
|
|
* @return mixed
|
2017-06-05 22:16:59 +02:00
|
|
|
*/
|
2017-09-03 17:37:51 +02:00
|
|
|
public function getUpdatedAttribute()
|
|
|
|
{
|
|
|
|
return $this->updated_at->diffForHumans();
|
2017-05-30 05:32:47 +02:00
|
|
|
}
|
2017-01-13 17:15:48 +01:00
|
|
|
}
|