when I try to dispatch a job from a controller it works.
however when I do the same from a repository it gives me an error.
<?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);
}
}
the error:
Call to undefined method App\Repositories\Retailer\CreateOrderRepo::dispatch()
Add the trait to dispatch the jobs:
use Illuminate\Foundation\Bus\DispatchesJobs;
change this
$this->dispatch($slackJob);
to this
dispatch($slackJob);
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