Despite the documentation declaring otherwise,尝试在Job类中设置连接名称可能会在Laravel中失败,并显示以下错误:
[Job Class] and Illuminate\Bus\Queueable define the same property ($connection) in the composition of [Job Class]. However, the definition differs and is considered incompatible. Class was composed
最佳答案
我相信这是PHP 7.3和Laravel 5.8之间的兼容性问题。由于Queueable特性已经定义了“连接”类变量,因此引发了错误。
要解决该错误,我们只需要设置变量而不是声明它即可。
破烂的职业:
class UpdateProductInventory implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public $connection = 'database';
}
固定职位类别:
class UpdateProductInventory implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $product;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct()
{
$this->connection = 'database';
}
}
关于php - * Job Class *和Illuminate\Bus\Queueable在* Job Class *的组成中定义了相同的属性($ connection),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/56340502/