目前在練習laravel廣播,照著網路教學做使用redis
使用下面這個寫法能夠把值寫進redis當中
// .env
BROADCAST_DRIVER=redis
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120
//
Redis::set('key',date('Y-m-d h:i:s'));
但是使用event就無法寫入
BROADCAST_DRIVER=log,可以正常寫入log檔案
換成redis就沒辦法也沒有報出錯誤,想請問如何解決
//event
class BroadEvents extends Event implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public $message;
/**
* Create a new event instance.
*
* @return void
*/
public function __construct($new_message)
{
//
$this->message=$new_message;
}
/**
* Get the channels the event should broadcast on.
*
* @return \Illuminate\Broadcasting\Channel|array
*/
public function broadcastOn()
{
// return new PrivateChannel('channel-name');
return new Channel('Achannel');
// return ['Achannel'];
}
}
//route
Route::get('/broad', function () {
$new_message['time']=date('Y-m-d h:i:s');
$new_message['msg']='test msg';
broadcast(new BroadEvents($new_message));
return 'ok';
});