Несмотря на то, что документация заявляет об обратном, попытка установить имя соединения в классе 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 уже определил переменную класса 'connection'.
Чтобы исправить ошибку, нам просто нужно установить переменную, а не объявить ее.
Сломанный класс работы:
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';
}
}
Была такая же проблема со свойством
$delay
. Это исправление ($delay
вместо$connection
) сработало для меня. Спасибо!