* Job Class *和Illuminate \ Bus \ Queueable在* Job Class *的组成中定义了相同的属性($ connection)

时间:2019-05-28 10:46:53

标签: php laravel console jobs

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

1 个答案:

答案 0 :(得分:1)

我相信这是PHP 7.3和Laravel 5.8之间的兼容性问题。由于Queueable特征已经定义了“连接”类变量,因此引发了错误。

要解决该错误,我们只需要设置变量而不是声明它即可。

工作类别损坏:

class UpdateProductInventory implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    public $connection = 'database';
    protected $product;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct(Product $product)
        $this->product = $product;
    }...

固定的工作类别:

class UpdateProductInventory implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    protected $product;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct(Product $product)
    {
        $this->connection = 'database';
        $this->product = $product;
    }...