XetaIO /
Xetaravel
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | namespace Xetaravel\Models; |
||
| 6 | |||
| 7 | use Eloquence\Behaviours\CountCache\CountedBy; |
||
| 8 | use Eloquence\Behaviours\CountCache\HasCounts; |
||
| 9 | use Illuminate\Database\Eloquent\Attributes\ObservedBy; |
||
| 10 | use Illuminate\Database\Eloquent\Relations\BelongsTo; |
||
| 11 | use Xetaio\Mentions\Models\Traits\HasMentionsTrait; |
||
| 12 | use Xetaravel\Models\Gates\FloodGate; |
||
| 13 | use Xetaravel\Models\Presenters\BlogCommentPresenter; |
||
| 14 | use Xetaravel\Observers\BlogCommentObserver; |
||
| 15 | |||
| 16 | #[ObservedBy([BlogCommentObserver::class])] |
||
| 17 | class BlogComment extends Model |
||
| 18 | { |
||
| 19 | use BlogCommentPresenter; |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 20 | use FloodGate; |
||
| 21 | use HasCounts; |
||
| 22 | use HasMentionsTrait; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * The attributes that are mass assignable. |
||
| 26 | * |
||
| 27 | * @var array |
||
| 28 | */ |
||
| 29 | protected $fillable = [ |
||
| 30 | 'blog_article_id', |
||
| 31 | 'content' |
||
| 32 | ]; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * The accessors to append to the model's array form. |
||
| 36 | * |
||
| 37 | * @var array |
||
| 38 | */ |
||
| 39 | protected $appends = [ |
||
| 40 | 'content_markdown', |
||
| 41 | 'comment_url' |
||
| 42 | ]; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * Get the user that owns the comment. |
||
| 46 | * |
||
| 47 | * @return BelongsTo |
||
| 48 | */ |
||
| 49 | #[CountedBy(as: 'blog_comment_count')] |
||
| 50 | public function user(): BelongsTo |
||
| 51 | { |
||
| 52 | return $this->belongsTo(User::class)->withTrashed(); |
||
| 53 | } |
||
| 54 | |||
| 55 | /** |
||
| 56 | * Get the article that owns the comment. |
||
| 57 | * |
||
| 58 | * @return BelongsTo |
||
| 59 | */ |
||
| 60 | #[CountedBy(as: 'blog_comment_count')] |
||
| 61 | public function article(): BelongsTo |
||
| 62 | { |
||
| 63 | return $this->belongsTo(BlogArticle::class, 'blog_article_id'); |
||
| 64 | } |
||
| 65 | } |
||
| 66 |