*/ protected $fillable = [ 'user_id', 'product_id', 'body', 'status', 'moderated_by', 'moderated_at', 'moderation_note', ]; /** * The attributes that should be cast. * * @var array */ protected $casts = [ 'moderated_at' => 'datetime', ]; /** * Get the user that owns the comment. */ public function user(): BelongsTo { return $this->belongsTo(User::class); } /** * Get the product that owns the comment. */ public function product(): BelongsTo { return $this->belongsTo(Product::class); } /** * Get the moderator who moderated the comment. */ public function moderator(): BelongsTo { return $this->belongsTo(User::class, 'moderated_by'); } /** * Check if comment is pending moderation. */ public function isPending(): bool { return $this->status === 'pending'; } /** * Check if comment is approved. */ public function isApproved(): bool { return $this->status === 'approved'; } /** * Check if comment is rejected. */ public function isRejected(): bool { return $this->status === 'rejected'; } }