38 lines
873 B
PHP
38 lines
873 B
PHP
<?php
|
|
|
|
namespace App\Events\Conversation;
|
|
|
|
use Illuminate\Broadcasting\Channel;
|
|
use Illuminate\Broadcasting\InteractsWithSockets;
|
|
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;
|
|
|
|
public $message;
|
|
|
|
/**
|
|
* Create a new event instance.
|
|
*/
|
|
public function __construct($message)
|
|
{
|
|
$this->message = $message->load('user');
|
|
}
|
|
|
|
/**
|
|
* Get the channels the event should broadcast on.
|
|
*
|
|
* @return array<int, Channel>
|
|
*/
|
|
public function broadcastOn(): array
|
|
{
|
|
return [
|
|
new PrivateChannel('chat.'.$this->message->conversation_id),
|
|
];
|
|
}
|
|
}
|