第二个参数未传递到 Laravel 5.1 中的事件


Second parameter not being passed to Event in Laravel 5.1

我正在尝试构造一个带有两个参数的事件,一个布尔值,然后是一个可能为空的第二个参数。有趣的是,我已经有一个事件使用完全相同的设置。但是我无法让第二个事件正常运行。

以下是功能事件:

namespace MyProj'Events'Live;
use MyProj'Events'Event;
use Illuminate'Queue'SerializesModels;
use Illuminate'Contracts'Broadcasting'ShouldBroadcast;
class LiveCountdownEvent extends Event  implements ShouldBroadcast
{
    use SerializesModels;
    public $isResuming;
    public $newTime;
    /**
     * Create a new event instance.
     *
     * @param $isResuming
     * @param null $newTime
     */
    public function __construct($isResuming, $newTime= null)
    {
        $this->isResuming = $isResuming;
        if ($newTime!= null) {
            $this->newTime= $newTime->format('Y-m-d H:i:s');
        }
    }
    /**
     * Get the channels the event should be broadcast on.
     *
     * @return array
     */
    public function broadcastOn()
    {
        return ['live-updates'];
    }
}

当它通过 websocket 在我的前端通过时:

对象 { isResuming: false, newTime: null }

这是非功能性事件,几乎没有任何更改。

<?php
namespace MyProj'Events;
use Illuminate'Queue'SerializesModels;
use Illuminate'Contracts'Broadcasting'ShouldBroadcast;
class WebcastEvent extends Event  implements ShouldBroadcast
{
    use SerializesModels;
    public $isActive;
    public $videoId;
    /**
     * Create a new event instance.
     *
     * @param $isActive
     * @param null $videoId
     */
    public function __construct($isActive, $videoId = null)
    {
        $this->isActive = $isActive;
        if ($videoId != null) {
            $this->videoId = $videoId;
        }
    }
    /**
     * Get the channels the event should be broadcast on.
     *
     * @return array
     */
    public function broadcastOn()
    {
        return ['live-updates'];
    }
}

这个不返回videoId,即使它是在我传递它时设置的(使用 Logging 语句,我确认事件构造正确(:

对象 { isActive: true }

注意到缺少videoId吗?这是怎么回事?

我已经创建了事件类并触发了它们,并且可以正常工作。

Event::fire(new LiveCountdownEvent(true));
Event::fire(new WebcastEvent(true));

日志:

[2015-12-03 12:24:21] local.INFO: Broadcasting [App'Events'LiveCountdownEvent] on channels [live-updates] with payload:
{
    "isResuming": true,
    "newTime": null
}  
[2015-12-03 12:24:21] local.INFO: Broadcasting [App'Events'WebcastEvent] on channels [live-updates] with payload:
{
    "isActive": true,
    "videoId": null
}

我知道我的回答不能解决你的问题,但它可能会帮助你面对问题。