laravel5.7 redis socket.io

作者: 刘满 分类: laravel 发布时间: 2018-12-02 21:50
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’));

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据