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()
This commit is contained in:
manukminasyan
2026-03-27 15:01:50 +04:00
parent b2ee8a1036
commit a4d4418963
10 changed files with 71 additions and 58 deletions

View File

@@ -61,12 +61,12 @@ class Project extends Model implements Commentable
Add the commenter trait to your User model:
```php
use Relaticle\Comments\Concerns\IsCommenter;
use Relaticle\Comments\Contracts\Commenter;
use Relaticle\Comments\Concerns\CanComment;
use Relaticle\Comments\Contracts\Commentator;
class User extends Authenticatable implements Commenter
class User extends Authenticatable implements Commentator
{
use IsCommenter;
use CanComment;
}
```

Binary file not shown.

View File

@@ -73,15 +73,15 @@ class Project extends Model implements Commentable
}
```
Add the `IsCommenter` trait to your User model:
Add the `CanComment` trait to your User model:
```php [app/Models/User.php]
use Relaticle\Comments\Concerns\IsCommenter;
use Relaticle\Comments\Contracts\Commenter;
use Relaticle\Comments\Concerns\CanComment;
use Relaticle\Comments\Contracts\Commentator;
class User extends Authenticatable implements Commenter
class User extends Authenticatable implements Commentator
{
use IsCommenter;
use CanComment;
}
```

View File

@@ -15,21 +15,34 @@ php artisan vendor:publish --tag=comments-config
This creates `config/comments.php` with all available options.
## Table Name
## Table Names
```php
'tables' => [
'table_names' => [
'comments' => 'comments',
'reactions' => 'comment_reactions',
'mentions' => 'comment_mentions',
'subscriptions' => 'comment_subscriptions',
'attachments' => 'comment_attachments',
],
```
Change the table name if it conflicts with your application.
Change the table names if they conflict with your application.
## Column Names
```php
'column_names' => [
'commenter_id' => 'commenter_id',
'commenter_type' => 'commenter_type',
],
```
## Models
```php
'models' => [
'comment' => \Relaticle\Comments\Comment::class,
'comment' => \Relaticle\Comments\Models\Comment::class,
],
'commenter' => [
@@ -178,10 +191,10 @@ When broadcasting is disabled, the Livewire component polls for new comments at
Override how the authenticated user is resolved:
```php
use Relaticle\Comments\Config;
use Relaticle\Comments\CommentsConfig;
// In AppServiceProvider::boot()
Config::resolveAuthenticatedUserUsing(function () {
CommentsConfig::resolveAuthenticatedUserUsing(function () {
return auth()->user();
});
```

View File

@@ -26,34 +26,34 @@ Create your own policy to customize authorization:
```php
namespace App\Policies;
use Relaticle\Comments\Comment;
use Relaticle\Comments\Contracts\Commenter;
use Relaticle\Comments\Models\Comment;
use Relaticle\Comments\Contracts\Commentator;
class CustomCommentPolicy
{
public function viewAny(Commenter $user): bool
public function viewAny(Commentator $user): bool
{
return true;
}
public function create(Commenter $user): bool
public function create(Commentator $user): bool
{
return true;
}
public function update(Commenter $user, Comment $comment): bool
public function update(Commentator $user, Comment $comment): bool
{
return $comment->user_id === $user->getKey()
&& $comment->user_type === $user->getMorphClass();
return $comment->commenter_id === $user->getKey()
&& $comment->commenter_type === $user->getMorphClass();
}
public function delete(Commenter $user, Comment $comment): bool
public function delete(Commentator $user, Comment $comment): bool
{
return $comment->user_id === $user->getKey()
return $comment->commenter_id === $user->getKey()
|| $user->hasRole('admin');
}
public function reply(Commenter $user, Comment $comment): bool
public function reply(Commentator $user, Comment $comment): bool
{
return $comment->canReply();
}

View File

@@ -48,4 +48,4 @@ Keys are stored in the database. If you change a key, existing reactions with th
## Storage
Reactions are stored in the `comment_reactions` table with a unique constraint on `(comment_id, user_id, user_type, reaction)`, ensuring one reaction of each type per user per comment.
Reactions are stored in the `comment_reactions` table with a unique constraint on `(comment_id, commenter_id, commenter_type, reaction)`, ensuring one reaction of each type per user per comment.

View File

@@ -63,7 +63,7 @@ When a comment is deleted, its attachments are cascade deleted from the database
## Helper Methods
The `CommentAttachment` model provides:
The `Attachment` model (`Relaticle\Comments\Models\Attachment`) provides:
```php
$attachment->isImage(); // Check if attachment is an image

View File

@@ -61,17 +61,17 @@ Users can toggle their subscription using the subscribe/unsubscribe button in th
### Programmatic Access
```php
use Relaticle\Comments\CommentSubscription;
use Relaticle\Comments\Models\Subscription;
// Check subscription status
CommentSubscription::isSubscribed($commentable, $user);
Subscription::isSubscribed($commentable, $user);
// Subscribe/unsubscribe
CommentSubscription::subscribe($commentable, $user);
CommentSubscription::unsubscribe($commentable, $user);
Subscription::subscribe($commentable, $user);
Subscription::unsubscribe($commentable, $user);
// Get all subscribers for a commentable
$subscribers = CommentSubscription::subscribersFor($commentable);
$subscribers = Subscription::subscribersFor($commentable);
```
## Events

View File

@@ -20,8 +20,8 @@ The main comments table with polymorphic relationships and threading support.
| `id` | bigint | Primary key |
| `commentable_type` | string | Polymorphic model type |
| `commentable_id` | bigint | Polymorphic model ID |
| `user_type` | string | Commenter model type |
| `user_id` | bigint | Commenter 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 |
@@ -39,12 +39,12 @@ Tracks emoji reactions per user per comment.
|--------|------|-------------|
| `id` | bigint | Primary key |
| `comment_id` | bigint | Foreign key to comments |
| `user_type` | string | Reactor model type |
| `user_id` | bigint | Reactor model ID |
| `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, user_id, user_type, reaction)`
**Unique constraint:** `(comment_id, commenter_id, commenter_type, reaction)`
### comment_mentions
@@ -54,11 +54,11 @@ Tracks @mentioned users per comment.
|--------|------|-------------|
| `id` | bigint | Primary key |
| `comment_id` | bigint | Foreign key to comments |
| `user_type` | string | Mentioned user model type |
| `user_id` | bigint | Mentioned user model ID |
| `commenter_type` | string | Mentioned user model type |
| `commenter_id` | bigint | Mentioned user model ID |
| `created_at` | timestamp | |
**Unique constraint:** `(comment_id, user_id, user_type)`
**Unique constraint:** `(comment_id, commenter_id, commenter_type)`
### comment_subscriptions
@@ -69,11 +69,11 @@ Tracks which users are subscribed to comment threads on specific models.
| `id` | bigint | Primary key |
| `commentable_type` | string | Subscribed model type |
| `commentable_id` | bigint | Subscribed model ID |
| `user_type` | string | Subscriber model type |
| `user_id` | bigint | Subscriber model ID |
| `commenter_type` | string | Subscriber model type |
| `commenter_id` | bigint | Subscriber model ID |
| `created_at` | timestamp | |
**Unique constraint:** `(commentable_type, commentable_id, user_type, user_id)`
**Unique constraint:** `(commentable_type, commentable_id, commenter_type, commenter_id)`
### comment_attachments
@@ -96,11 +96,11 @@ Stores file attachment metadata for comments.
```
Commentable Model (e.g., Project)
└── comments (morphMany)
├── user (morphTo → User)
├── commenter (morphTo → User)
├── parent (belongsTo → Comment)
├── replies (hasMany → Comment)
├── reactions (hasMany → CommentReaction)
├── attachments (hasMany → CommentAttachment)
├── reactions (hasMany → Reaction)
├── attachments (hasMany → Attachment)
└── mentions (morphToMany → User)
```

View File

@@ -31,12 +31,12 @@ class Project extends Model implements Commentable
```
```php
use Relaticle\Comments\Concerns\IsCommenter;
use Relaticle\Comments\Contracts\Commenter;
use Relaticle\Comments\Concerns\CanComment;
use Relaticle\Comments\Contracts\Commentator;
class User extends Authenticatable implements Commenter
class User extends Authenticatable implements Commentator
{
use IsCommenter;
use CanComment;
}
```
@@ -113,7 +113,7 @@ Publish config: `php artisan vendor:publish --tag=comments-config`
| Key | Default | Purpose |
|-----|---------|---------|
| `tables.comments` | `'comments'` | Main comments table name |
| `table_names.comments` | `'comments'` | Main comments table name |
| `models.comment` | `Comment::class` | Comment model class |
| `commenter.model` | `User::class` | Commenter (user) model class |
| `policy` | `CommentPolicy::class` | Authorization policy class |
@@ -183,14 +183,14 @@ Default `CommentPolicy` methods:
```php
namespace App\Policies;
use Relaticle\Comments\Comment;
use Relaticle\Comments\Contracts\Commenter;
use Relaticle\Comments\Models\Comment;
use Relaticle\Comments\Contracts\Commentator;
class CustomCommentPolicy
{
public function delete(Commenter $user, Comment $comment): bool
public function delete(Commentator $user, Comment $comment): bool
{
return $comment->user_id === $user->getKey()
return $comment->commenter_id === $user->getKey()
|| $user->hasRole('admin');
}
}
@@ -201,10 +201,10 @@ class CustomCommentPolicy
### Scoped Comments (Multi-tenancy)
```php
use Relaticle\Comments\Config;
use Relaticle\Comments\CommentsConfig;
// In AppServiceProvider::boot()
Config::resolveAuthenticatedUserUsing(function () {
CommentsConfig::resolveAuthenticatedUserUsing(function () {
return auth()->user();
});
```
@@ -276,7 +276,7 @@ $model->commentCount(); // Total count
// On Comment model
$comment->commentable(); // Parent model (morphTo)
$comment->user(); // Commenter (morphTo)
$comment->commenter(); // Commenter (morphTo)
$comment->parent(); // Parent comment (belongsTo)
$comment->replies(); // Child comments (hasMany)
$comment->reactions(); // Reactions (hasMany)