【发布时间】:2018-07-31 00:11:26
【问题描述】:
我正在尝试将接口实现到作业中,但没有运气。是否可以在公共构造中实现接口/存储库并在作业的handle() 方法中使用所述接口?
我得到的错误如下:
Argument 1 passed to App\Jobs\OrderCreate::__construct() must be an instance of App\Http\Interfaces\OrderInterface, string given, called in /Users/Panoply/Sites/stock-sync/app/Http/Controllers/StockController.php on line 31
以下是我想要实现的基本设置。
库存控制人:
public function test(){
dispatch(new OrderCreate('hello'));
}
订单创建工作:
protected $order;
protected $test;
public function __construct(OrderInterface $order, $test)
{
$this->order = $order;
$this->test = $test;
}
public function handle()
{
$this->order->test($this->test);
}
订单仓库:
class OrderRepository implements OrderInterface
{
public function test($data) {
error_log($data);
}
}
订单接口:
public function test($data);
在我的控制器和命令中实现这种模式没有任何问题,但我似乎无法让它在作业中运行。
【问题讨论】:
标签: php laravel laravel-5 lumen