From b5d2606fd7ce2cd22f71fd6d7259ea85384cf271 Mon Sep 17 00:00:00 2001 From: wanghongjun <1445693971@qq.com> Date: Fri, 4 Sep 2026 16:06:16 +0800 Subject: [PATCH] =?UTF-8?q?ws=E6=B5=8B=E8=AF=953?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Events/SendAnnouncement.php | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/app/Events/SendAnnouncement.php b/app/Events/SendAnnouncement.php index af54fbc..c29be2a 100644 --- a/app/Events/SendAnnouncement.php +++ b/app/Events/SendAnnouncement.php @@ -2,6 +2,7 @@ namespace App\Events; +use Carbon\Carbon; use Illuminate\Broadcasting\Channel; use Illuminate\Broadcasting\InteractsWithSockets; use Illuminate\Contracts\Broadcasting\ShouldBroadcast; @@ -12,31 +13,25 @@ class SendAnnouncement implements ShouldBroadcast { use Dispatchable, InteractsWithSockets, SerializesModels; - public $message; - - public function __construct($message) - { - $this->message = $message; - } + public string $message; + public string $broadcastTime; /** - * 指定事件广播到的频道 + * Create a new event instance. */ - public function broadcastOn(): array - { - return [ - new Channel('chat'), // 公共频道 - ]; + public function __construct(string $message) { + $this->message = $message; + $this->broadcastTime = Carbon::now()->toDateTimeString(); } /** - * 可选:自定义广播数据 + * Get the channels the event should broadcast on. + * + * @return array */ - public function broadcastWith(): array - { + public function broadcastOn(): array { return [ - 'message' => $this->message, - 'time' => now()->toDateTimeString(), + new Channel('chat'), ]; } }