- Rename IsCommenter trait to CanComment, Commenter interface to Commentator - Move models to Models/ namespace (Comment, Reaction, Attachment, Subscription) - Rename user_type/user_id polymorphic columns to commenter_type/commenter_id - Rename Config class to CommentsConfig, update config key tables->table_names - Rename getCommentName() to getCommentDisplayName() on commentator models - Add column_names config section for commenter morph customization - Add table_names config with all 5 tables individually configurable - Expand translation file with structured i18n groups - Update all Blade views, Livewire components, events, listeners, and tests
52 lines
1.5 KiB
PHP
52 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace Relaticle\Comments\Events;
|
|
|
|
use Illuminate\Broadcasting\InteractsWithBroadcasting;
|
|
use Illuminate\Broadcasting\PrivateChannel;
|
|
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Foundation\Events\Dispatchable;
|
|
use Illuminate\Queue\SerializesModels;
|
|
use Relaticle\Comments\CommentsConfig;
|
|
use Relaticle\Comments\Models\Comment;
|
|
|
|
class CommentDeleted implements ShouldBroadcast
|
|
{
|
|
use Dispatchable;
|
|
use InteractsWithBroadcasting;
|
|
use SerializesModels;
|
|
|
|
public readonly Model $commentable;
|
|
|
|
public function __construct(public readonly Comment $comment)
|
|
{
|
|
$this->commentable = $comment->commentable;
|
|
}
|
|
|
|
/** @return array<int, PrivateChannel> */
|
|
public function broadcastOn(): array
|
|
{
|
|
$prefix = CommentsConfig::getBroadcastChannelPrefix();
|
|
|
|
return [
|
|
new PrivateChannel("{$prefix}.{$this->comment->commentable_type}.{$this->comment->commentable_id}"),
|
|
];
|
|
}
|
|
|
|
public function broadcastWhen(): bool
|
|
{
|
|
return CommentsConfig::isBroadcastingEnabled();
|
|
}
|
|
|
|
/** @return array{comment_id: int|string, commentable_type: string, commentable_id: int|string} */
|
|
public function broadcastWith(): array
|
|
{
|
|
return [
|
|
'comment_id' => $this->comment->id,
|
|
'commentable_type' => $this->comment->commentable_type,
|
|
'commentable_id' => $this->comment->commentable_id,
|
|
];
|
|
}
|
|
}
|