Laravel作业中间件WithoutOverlapping-在初始化之前不得访问(php)



我正在使用带有PHP 7.4的Laravel 8,并试图实现一个具有";WithoutOverlapping";。

作业被分派到一个具有参数"的队列上;1〃;,当作业在队列上执行时,我收到以下错误:

$hotelID must not be accessed before initialization

似乎在中间件之前没有调用__construct方法,我如何将密钥传递给WithoutOverlapping的类构造函数?

class DeleteHotel implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, HotelContentCache;
private int $hotelID;
public function __construct(int $hotelID)
{
$this->hotelID = $hotelID;
}
public function middleware(): array
{
return [(new WithoutOverlapping($this->hotelID))->releaseAfter(10)];
}
}

您必须更改

private int $hotelID;

protected int $hotelID;

它会起作用的。

最新更新