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
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';
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With