Essentials
Database Schema
Tables, relationships, and indexes used by the Comments package.
Tables
Five tables are created by the package migrations.
comments
The main comments table with polymorphic relationships and threading support.
| Column | Type | Description |
|---|---|---|
id | bigint | Primary key |
commentable_type | string | Polymorphic model type |
commentable_id | bigint | Polymorphic model ID |
commenter_type | string | Commenter model type |
commenter_id | bigint | Commenter model ID |
parent_id | bigint (nullable) | Parent comment for replies |
body | text | HTML comment content |
edited_at | timestamp (nullable) | When the comment was last edited |
deleted_at | timestamp (nullable) | Soft delete timestamp |
created_at | timestamp | |
updated_at | timestamp |
Indexes: (commentable_type, commentable_id, parent_id)
comment_reactions
Tracks emoji reactions per user per comment.
| Column | Type | Description |
|---|---|---|
id | bigint | Primary key |
comment_id | bigint | Foreign key to comments |
commenter_type | string | Reactor model type |
commenter_id | bigint | Reactor model ID |
reaction | string | Reaction key (e.g., thumbs_up) |
created_at | timestamp |
Unique constraint: (comment_id, commenter_id, commenter_type, reaction)
comment_mentions
Tracks @mentioned users per comment.
| Column | Type | Description |
|---|---|---|
id | bigint | Primary key |
comment_id | bigint | Foreign key to comments |
commenter_type | string | Mentioned user model type |
commenter_id | bigint | Mentioned user model ID |
created_at | timestamp |
Unique constraint: (comment_id, commenter_id, commenter_type)
comment_subscriptions
Tracks which users are subscribed to comment threads on specific models.
| Column | Type | Description |
|---|---|---|
id | bigint | Primary key |
commentable_type | string | Subscribed model type |
commentable_id | bigint | Subscribed model ID |
commenter_type | string | Subscriber model type |
commenter_id | bigint | Subscriber model ID |
created_at | timestamp |
Unique constraint: (commentable_type, commentable_id, commenter_type, commenter_id)
comment_attachments
Stores file attachment metadata for comments.
| Column | Type | Description |
|---|---|---|
id | bigint | Primary key |
comment_id | bigint | Foreign key to comments |
file_path | string | Path on the storage disk |
original_name | string | Original uploaded filename |
mime_type | string | File MIME type |
size | bigint | File size in bytes |
disk | string | Laravel filesystem disk |
created_at | timestamp | |
updated_at | timestamp |
Relationships
Commentable Model (e.g., Project)
└── comments (morphMany)
├── commenter (morphTo → User)
├── parent (belongsTo → Comment)
├── replies (hasMany → Comment)
├── reactions (hasMany → Reaction)
├── attachments (hasMany → Attachment)
└── mentions (morphToMany → User)
All relationships are polymorphic, allowing the same comment system to work across any number of models in your application.