推杆未触发事件不起作用Laravel

时间:2019-12-01 10:38:43

标签: php laravel-5 pusher pusher-js

我正在尝试触发pusher事件,但是它不起作用。

class SendWaitingForRedirect implements ShouldBroadcast
{
    use Dispatchable, InteractsWithSockets, SerializesModels;

    public $message;

    public function __construct($message)
    {
        $this->message = $message;
    }

    public function broadcastOn()
    {
        return ['my-channel'];
    }

    public function broadcastAs()
    {
        return 'my-event';
    }
}

并将事件称为

event(new \App\Events\SendWaitingForRedirect('hello world'));

我不知道怎么了。 你能帮忙吗?

我检查了推杆上的错误。它没有任何错误。 你能帮忙吗?

1 个答案:

答案 0 :(得分:0)

您没有使用正确的通道和事件语法。语法看起来像这样

class SendWaitingForRedirect implements ShouldBroadcast
 {
use Dispatchable, InteractsWithSockets, SerializesModels;

public $message;

public function __construct($message)
{
    $this->message = $message;
}

public function broadcastOn()
{
     return new Channel('my-channel');//Use the different type of channel as you want

}

public function broadcastAs()
{
    return $this->message; //Return data as you want
}
}

希望有帮助。