composer require predis/predis
.env
BROADCAST_DRIVER=redis
config/app.php
取消注释providers下App\Providers\BroadcastServiceProvider::class,
创建文件app/Events/ChatRoom.php
<?php namespace App\Events; use Illuminate\Contracts\Broadcasting\ShouldBroadcast; class ChatRoom implements ShouldBroadcast { public $data; private $channels; /** * Create a new event instance. * * @return void */ public function __construct($channels, $data) { // $this->channels = $channels; $this->data = $data; } /** * Get the channels the event should be broadcast on. * * @return array */ public function broadcastOn() { return $this->channels; } }
调用
use Event, App\Events\ChatRoom;
Event::fire(new ChatRoom($channel, ‘data’));