feat: Implement real-time chat with Reverb

This commit is contained in:
Daan Meijer
2026-06-15 00:44:55 +02:00
parent f8ee8165ff
commit 9cb87b61ef
13 changed files with 1267 additions and 5 deletions
+44
View File
@@ -0,0 +1,44 @@
<?php
namespace App\Events;
use App\Models\Message;
use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
class MessageSent implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;
/**
* Create a new event instance.
*/
public function __construct(public Message $message)
{
//
}
/**
* Get the channels the event should broadcast on.
*
* @return array<int, Channel>
*/
public function broadcastOn(): array
{
return [
new PrivateChannel('chats.'.$this->message->chat_id),
];
}
public function broadcastWith(): array
{
return [
'message' => $this->message->load('user'),
];
}
}