Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

*Job Class* and Illuminate\Bus\Queueable define the same property ($connection) in the composition of *Job Class*

Despite the documentation declaring otherwise, attempting to set the connection name within a Job class can fail in Laravel with the error:

[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
like image 293
RonnyKnoxville Avatar asked May 28 '19 10:05

RonnyKnoxville


1 Answers

I believe this is a compatibility issue between PHP 7.3 and Laravel 5.8. The error is raised because the Queueable trait has already defined the 'connection' class variable.

To fix the error, we just need to set the variable rather than declare it.

Broken job class:

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

    public $connection = 'database';
}

Fixed job class:

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

    protected $product;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->connection = 'database';
    }
}
like image 146
RonnyKnoxville Avatar answered Nov 08 '22 20:11

RonnyKnoxville