lundi 30 juillet 2018

Implement a Repository Interface into Job

I am trying to implement an Interface into a Job but having no luck. Is it possible to implement an interface / repository within the public construct and use said interface in the handle() method of the Job?

The error I am getting is as follows:

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

Below is a basic setup of what I am trying to achieve.

Stock Controller:

public function test(){
   dispatch(new OrderCreate('hello'));
}

OrderCreate Job:

protected $order;
protected $test;

public function __construct(OrderInterface $order, $test)
{
    $this->order = $order;
    $this->test = $test;
}

public function handle()
{
    $this->order->test($this->test);
}

OrderRepository:

class OrderRepository implements OrderInterface
{
    public function test($data) {
        error_log($data);
    }
}

OrderInterface:

public function test($data);

I have had no troubles implementing this pattern into my controllers and commands but I can't seem to get it working on a Job.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire