Files
relaticle-comments/docs/content/2.essentials/5.attachments.md
manukminasyan a4d4418963 docs: update all documentation for refactored naming conventions
- CanComment trait replaces IsCommenter
- Commentator interface replaces Commenter
- Models moved to Models\ namespace (Comment, Reaction, Attachment, Subscription)
- commenter_type/commenter_id columns replace user_type/user_id
- CommentsConfig replaces Config class
- table_names config key replaces tables
- getCommentDisplayName() replaces getCommentName()
2026-03-27 15:01:50 +04:00

1.9 KiB

title, description, navigation, seo
title description navigation seo
Attachments File uploads for comments.
icon
i-lucide-paperclip
description
Configure file attachments for comments.

Overview

Comments support file attachments for both images and documents. Images are displayed inline within the comment body, while documents appear as downloadable links.

Configuration

// config/comments.php
'attachments' => [
    'enabled' => true,
    'disk' => 'public',
    'max_size' => 10240, // KB (10 MB)
    'allowed_types' => [
        'image/jpeg',
        'image/png',
        'image/gif',
        'image/webp',
        'application/pdf',
        'text/plain',
        'application/msword',
        'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
    ],
],
Key Default Description
enabled true Show/hide the attachment upload UI
disk 'public' Laravel filesystem disk for storage
max_size 10240 Maximum file size in kilobytes
allowed_types images, pdf, text, word Array of allowed MIME types

Disabling Attachments

'attachments' => [
    'enabled' => false,
],

This removes the file upload UI from the comment form entirely.

Storage

Attachments are stored via Livewire's file upload mechanism. Each attachment record tracks:

  • file_path -- Path on the configured disk
  • original_name -- Original filename for display
  • mime_type -- MIME type for rendering decisions
  • size -- File size in bytes
  • disk -- Storage disk name

When a comment is deleted, its attachments are cascade deleted from the database. The physical files are removed from the disk.

Helper Methods

The Attachment model (Relaticle\Comments\Models\Attachment) provides:

$attachment->isImage();       // Check if attachment is an image
$attachment->url();           // Get the storage URL
$attachment->formattedSize(); // Human-readable size (e.g., "2.5 MB")