Reputation: 929
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.
Upvotes: 2
Views: 1178
Reputation: 929
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
Upvotes: 2