| 12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- <?php
- namespace App\Events;
- use Illuminate\Broadcasting\Channel;
- use Illuminate\Broadcasting\InteractsWithSockets;
- use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
- use Illuminate\Foundation\Events\Dispatchable;
- use Illuminate\Queue\SerializesModels;
- class SendWebSocketMessageEvent implements ShouldBroadcastNow
- {
- use Dispatchable, InteractsWithSockets, SerializesModels;
- const CHANNEL = 'actions';
- /**
- * Create a new event instance.
- */
- public function __construct(private readonly string $message, private readonly int $userId, private readonly array $payload)
- {
- //
- }
- /**
- * Get the channels the event should broadcast on.
- *
- * @return Channel
- */
- public function broadcastOn(): Channel
- {
- return new Channel(self::CHANNEL); }
- public function broadcastWith(): array
- {
- return [
- 'action' => 'message',
- 'message' => $this->message,
- 'user_id' => $this->userId,
- 'payload' => $this->payload,
- ];
- }
- }
|