0

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

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'));

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

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

4

1 回答 1

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
}
}

希望能帮助到你。

于 2019-12-01T11:45:12.133 回答