当我尝试从控制器发送作业时它起作用.
但是,当我从存储库中执行相同操作时,它会给我一个错误.
<?php
namespace App\Repositories\Retailer;
use App\Jobs\SlackJob;
use App\Traits\CreateOrderTrait;
class CreateOrderRepo
{
use CreateOrderTrait;
public function create($store_id)
{
$slackJob = new SlackJob("Test", 1);
$slackJob = $slackJob->onQueue('high');
$this->dispatch($slackJob);
}
}
错误:
Call to undefined method App\Repositories\Retailer\CreateOrderRepo::dispatch()
解决方法:
添加特征以分派作业:
use Illuminate\Foundation\Bus\DispatchesJobs;