|
|
|
@ -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<int, Channel> |
|
|
|
*/ |
|
|
|
public function broadcastWith(): array |
|
|
|
{ |
|
|
|
public function broadcastOn(): array { |
|
|
|
return [ |
|
|
|
'message' => $this->message, |
|
|
|
'time' => now()->toDateTimeString(), |
|
|
|
new Channel('chat'), |
|
|
|
]; |
|
|
|
} |
|
|
|
} |
|
|
|
|