| 123456789101112131415161718192021222324252627282930 |
- <?php
- namespace App\Broadcasting\Events;
- use App\Broadcasting\Events\WebsocketEventInterface;
- use App\Broadcasting\Entity\WebsocketEventData;
- use Illuminate\Broadcasting\Channel;
- use Illuminate\Broadcasting\InteractsWithSockets;
- use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
- use Illuminate\Foundation\Events\Dispatchable;
- use Illuminate\Queue\SerializesModels;
- final class WebsocketEvent implements WebsocketEventInterface, ShouldBroadcastNow
- {
- use Dispatchable, InteractsWithSockets, SerializesModels;
- public function __construct(
- private readonly WebsocketEventData $dto
- ) {}
- public function broadcastOn(): Channel
- {
- return new Channel($this->dto->channelName());
- }
- public function broadcastWith(): array
- {
- return ['data' => $this->dto->data];
- }
- }
|