45 lines
963 B
PHP
45 lines
963 B
PHP
|
<?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 MessageSent implements ShouldBroadcastNow
|
||
|
{
|
||
|
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||
|
|
||
|
public $message;
|
||
|
public $user_id;
|
||
|
public $name;
|
||
|
/**
|
||
|
* Create a new event instance.
|
||
|
*/
|
||
|
public function __construct($message, $user_id, $name)
|
||
|
{
|
||
|
$this->message = $message;
|
||
|
$this->user_id = $user_id;
|
||
|
$this->name = $name;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Get the channels the event should broadcast on.
|
||
|
*
|
||
|
* @return array
|
||
|
*/
|
||
|
public function broadcastOn(): array
|
||
|
{
|
||
|
return [
|
||
|
new Channel('chatroom'),
|
||
|
];
|
||
|
}
|
||
|
|
||
|
public function broadcastAs(): string
|
||
|
{
|
||
|
return 'message.sent';
|
||
|
}
|
||
|
}
|