Files
construprogress/app/Notifications/IssueCommentedNotification.php
T

43 lines
1.3 KiB
PHP
Raw Normal View History

<?php
namespace App\Notifications;
use App\Models\IssueComment;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Notifications\Notification;
use Illuminate\Support\Str;
class IssueCommentedNotification extends Notification implements ShouldBroadcast
{
use Queueable;
public function __construct(public IssueComment $comment) {}
public function via($notifiable): array
{
return ['database', 'broadcast'];
}
public function toArray($notifiable): array
{
$issue = $this->comment->issue;
return [
2026-08-28 13:04:28 +02:00
'type' => 'issue_commented',
'issue_id' => $this->comment->issue_id,
'project_id' => $issue?->project_id,
2026-08-28 13:04:28 +02:00
'author' => $this->comment->user?->name,
'message' => "{$this->comment->user?->name} comentó en '{$issue?->title}': ".Str::limit($this->comment->body, 60),
];
}
public function broadcastOn(): array
{
$issue = $this->comment->issue;
$userIds = [];
if ($issue->assigned_to) $userIds[] = $issue->assigned_to;
if ($issue->reported_by) $userIds[] = $issue->reported_by;
return array_map(fn ($id) => new \Illuminate\Broadcasting\PrivateChannel("user.{$id}"), array_unique($userIds));
}
}