我正在使用laravel 5.5。我将 BROADCAST_DRIVER 设置为日志,但是当我访问链接以触发事件时,没有任何反应。 laravel.log 文件仍为空。我已在config / app.php上取消注释 BroadcastServiceProvider 。这是我的代码
.ENV
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=myDatabase
DB_USERNAME=root
DB_PASSWORD=numberPassword
BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=database
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
配置/ app.php
App\Providers\AppServiceProvider::class,
App\Providers\AuthServiceProvider::class,
App\Providers\BroadcastServiceProvider::class,
App\Providers\EventServiceProvider::class,
App\Providers\RouteServiceProvider::class,
应用/活动/ ReloadTableEvent.php
class ReloadTableEvent implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;
protected $coinData;
public function __construct($coinData)
{
$this->coinData = $coinData;
}
public function broadcastWith()
{
return ['coin' => $this->coinData];
}
public function broadcastAs()
{
return 'reload-event';
}
public function broadcastOn()
{
return new Channel('reload-channel');
}
}
应用/ HTTP /控制器/ ReloadTableController.php
public function reloadTable()
{
$coin = Coin::take(50)->get();
$event = new ReloadTableEvent($coin);
event($event);
}
我已经这样做了
仍然没有。我该怎么办?
更新1
我还没有使用听众。当我创建新项目,并为我当前的项目设置相同的选项时,它可以工作。
存储/记录/ laravel.log
[2018-01-08 06:24:02] local.INFO: Broadcasting [reload-event] on channels [reload-channel] with payload:
{
"coin": {
"name": "Test"
},
"socket": null
}
答案 0 :(得分:0)
您应该按group_by