Laravel:推杆事件不会在雄辩的事件听众中播出 [英] Laravel: Pusher events do not broadcast from within eloquent's event listener

查看:177
本文介绍了Laravel:推杆事件不会在雄辩的事件听众中播出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在有声的事件听众中,我使用Pusher进行事件广播的问题。我的事件正在被解雇,并从Laravel控制器完全发出。然而,当我从我的口才事件听众中触发他们时,广播似乎并没有真正触及到。



boot app / Providers / AppServiceProvider.php 的$ c>方法包含:

  MyModel :: saving(function($ record){
doSomeStuf();

//触发事件
$ pusher = \App :: make('pusher' );
$ channel = $ record-> username;
$ pusher-> trigger($ channel,'status-changed',$ record);

doSomeOtherStuf );

return true;
});

订阅该事件的js文件在放置相同代码时监听事件没有问题在控制器中。



另请注意, doSomeStuf() doSomeOtherStuf() code>执行得很好,没有异常抛出。

解决方案

原来是一个日期同步问题。 / p>

我的本​​地服务器是Ubuntu机器,而我的实时服务器在CentOS上运行。运行以下命令解决了这个问题:



Ubuntu:



sudo ntpdate ntp。 ubuntu.com



CentOS:



sudo ntpdate pool.ntp.org


I'm having issues doing event broadcasting using Pusher from within an Eloquent event listener. My event are being fired and sent out from Laravel controller perfectly. However, it seems that the broadcasts are not actually reaching pusher when I trigger them from within my Eloquent event listener.

The boot method of my app/Providers/AppServiceProvider.php contains:

MyModel::saving(function($record){
    doSomeStuf();

    // trigger event
    $pusher = \App::make('pusher');
    $channel = $record->username;
    $pusher->trigger($channel, 'status-changed', $record);

    doSomeOtherStuf();

    return true;
});

The js file that subscribes to the event has no problem listening to the event when the same code is placed in a controller.

Also note that doSomeStuf() and doSomeOtherStuf() are executed quite fine and no exception is thrown.

解决方案

Turned out to be a date synchronization issue.

My local server is an Ubuntu machine while my live server is running on CentOS. Running the following commands solved the problem:

Ubuntu:

sudo ntpdate ntp.ubuntu.com

CentOS:

sudo ntpdate pool.ntp.org

这篇关于Laravel:推杆事件不会在雄辩的事件听众中播出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆