我正在使用laravel 5.8开发一个多租户应用程序,并且我正在使用this来为该工作设置相关的租户ID,但是当我从这样的控制台分派工作时
$websites = \Hyn\Tenancy\Models\Website::all();
foreach ($websites as $website) {
$environment = $this->app->make(\Hyn\Tenancy\Environment::class);
$environment->tenant($website);
$schedule->call(function() use ($website){Bus::dispatch((new FetchCallsData()));})->hourly();
}
,在buildDatabaseRecord
中,当我尝试获取当前网站时,我将拥有foreach
中的最后一个网站。我发现buildDatabaseRecord
将通过事件异步运行,因此当前网站在buildDatabaseRecord
protected function buildDatabaseRecord($queue, $payload, $availableAt, $attempts = 0)
{
$queueRecord = [
'queue' => $queue,
'attempts' => $attempts,
'reserved_at' => null,
'available_at' => $availableAt,
'created_at' => $this->currentTime(),
'payload' => $payload,
];
$website = app(\Hyn\Tenancy\Environment::class)->tenant();
//here is the issue and I get last website in foreach loop for all jobs
$queueRecord['tenant_id']=$website->id
//also I tried using global variables but same result
/*if(isset( $_SERVER['tenant_id']))
$queueRecord['tenant_id'] = $_SERVER['tenant_id'];*/
return $queueRecord;
}
我认为我需要在工作中添加onTenant($website)
或类似的内容?