From 11d67ffba58686a422e31e05eacb8211b03730af Mon Sep 17 00:00:00 2001 From: Sevan Nerse Date: Wed, 11 Mar 2020 22:16:52 +0300 Subject: [PATCH] CreateTransaction job is improved --- app/Events/Banking/TransactionCreated.php | 22 ++++++++++++++++++++++ app/Events/Banking/TransactionCreating.php | 22 ++++++++++++++++++++++ app/Jobs/Banking/CreateTransaction.php | 16 ++++++++++++---- 3 files changed, 56 insertions(+), 4 deletions(-) create mode 100644 app/Events/Banking/TransactionCreated.php create mode 100644 app/Events/Banking/TransactionCreating.php diff --git a/app/Events/Banking/TransactionCreated.php b/app/Events/Banking/TransactionCreated.php new file mode 100644 index 000000000..d7da55c57 --- /dev/null +++ b/app/Events/Banking/TransactionCreated.php @@ -0,0 +1,22 @@ +transaction = $transaction; + } +} diff --git a/app/Events/Banking/TransactionCreating.php b/app/Events/Banking/TransactionCreating.php new file mode 100644 index 000000000..1e3252625 --- /dev/null +++ b/app/Events/Banking/TransactionCreating.php @@ -0,0 +1,22 @@ +request = $request; + } +} diff --git a/app/Jobs/Banking/CreateTransaction.php b/app/Jobs/Banking/CreateTransaction.php index 7b03c2f41..6c31ca9ea 100644 --- a/app/Jobs/Banking/CreateTransaction.php +++ b/app/Jobs/Banking/CreateTransaction.php @@ -4,10 +4,14 @@ namespace App\Jobs\Banking; use App\Abstracts\Job; use App\Models\Banking\Transaction; +use App\Events\Banking\TransactionCreated; +use App\Events\Banking\TransactionCreating; class CreateTransaction extends Job { protected $request; + + protected $transaction; /** * Create a new job instance. @@ -26,18 +30,22 @@ class CreateTransaction extends Job */ public function handle() { - $transaction = Transaction::create($this->request->all()); + event(new TransactionCreating($this->request)); + + $this->transaction = Transaction::create($this->request->all()); // Upload attachment if ($this->request->file('attachment')) { $media = $this->getMedia($this->request->file('attachment'), 'transactions'); - $transaction->attachMedia($media, 'attachment'); + $this->transaction->attachMedia($media, 'attachment'); } // Recurring - $transaction->createRecurring(); + $this->transaction->createRecurring(); - return $transaction; + event(new TransactionCreated($this->transaction)); + + return $this->transaction; } }