我试图在Laravel中重写一些代码以使其成为一项工作,并且我正在做以下事情:
$subscriptions->each(function ($sub) use ($payload) {
$channel = $this;
// new code
dispatch(new SendOnePushNotification($channel, $sub, $payload));
// old code below
/*$this->webPush->sendNotification(
$sub->endpoint,
$payload,
$sub->public_key,
$sub->auth_token
);*/
});
造成这种情况的原因是将$ this传递给SendOnePushNotification构造函数。
我的猜测是我可以用某种方式改写这个,但我不确定如何开始。有什么建议吗?