Ale*_*ris 1 php socket.io laravel pusher
在事件上使用时是否有一种简单的方法来有条件地广播implement ShouldBroadcast?例如:
/**
* Get the channels the event should be broadcast on.
*
* @return array
*/
public function broadcastOn()
{
if ($x == 2) return;
return ['test_channel'];
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,上面的代码仍然创建排队作业,它没有成功并继续尝试它,但不能,因为它没有通道名称。有没有一种简单的方法来抑制正在创建的工作$x == 2?
只需添加此内容即可,因为 Laravel 现在支持broadcastWhen()涵盖此场景的事件方法。
例如;
// on an event class...
public function broadcastWhen(){
// check for whatever here
return $bool;
}
Run Code Online (Sandbox Code Playgroud)