added pointer interfaces for jobs
This commit is contained in:
@ -5,52 +5,34 @@ namespace App\Jobs\Banking;
|
||||
use App\Abstracts\Job;
|
||||
use App\Events\Banking\TransactionCreated;
|
||||
use App\Events\Banking\TransactionCreating;
|
||||
use App\Interfaces\Job\HasOwner;
|
||||
use App\Interfaces\Job\ShouldCreate;
|
||||
use App\Models\Banking\Transaction;
|
||||
|
||||
class CreateTransaction extends Job
|
||||
class CreateTransaction extends Job implements HasOwner, ShouldCreate
|
||||
{
|
||||
protected $transaction;
|
||||
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @param $request
|
||||
*/
|
||||
public function __construct($request)
|
||||
{
|
||||
$this->request = $this->getRequestInstance($request);
|
||||
$this->request->merge(['created_by' => user_id()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return Transaction
|
||||
*/
|
||||
public function handle()
|
||||
public function handle(): Transaction
|
||||
{
|
||||
event(new TransactionCreating($this->request));
|
||||
|
||||
\DB::transaction(function () {
|
||||
$this->transaction = Transaction::create($this->request->all());
|
||||
$this->model = Transaction::create($this->request->all());
|
||||
|
||||
// Upload attachment
|
||||
if ($this->request->file('attachment')) {
|
||||
foreach ($this->request->file('attachment') as $attachment) {
|
||||
$media = $this->getMedia($attachment, 'transactions');
|
||||
|
||||
$this->transaction->attachMedia($media, 'attachment');
|
||||
$this->model->attachMedia($media, 'attachment');
|
||||
}
|
||||
}
|
||||
|
||||
// Recurring
|
||||
$this->transaction->createRecurring($this->request->all());
|
||||
$this->model->createRecurring($this->request->all());
|
||||
});
|
||||
|
||||
event(new TransactionCreated($this->transaction));
|
||||
event(new TransactionCreated($this->model));
|
||||
|
||||
return $this->transaction;
|
||||
return $this->model;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user