added account events
This commit is contained in:
parent
fe6b6188b9
commit
271b61808b
21
app/Events/Banking/AccountCreated.php
Normal file
21
app/Events/Banking/AccountCreated.php
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Events\Banking;
|
||||||
|
|
||||||
|
use App\Abstracts\Event;
|
||||||
|
use App\Models\Banking\Account;
|
||||||
|
|
||||||
|
class AccountCreated extends Event
|
||||||
|
{
|
||||||
|
public $account;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new event instance.
|
||||||
|
*
|
||||||
|
* @param $account
|
||||||
|
*/
|
||||||
|
public function __construct(Account $account)
|
||||||
|
{
|
||||||
|
$this->account = $account;
|
||||||
|
}
|
||||||
|
}
|
20
app/Events/Banking/AccountCreating.php
Normal file
20
app/Events/Banking/AccountCreating.php
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Events\Banking;
|
||||||
|
|
||||||
|
use App\Abstracts\Event;
|
||||||
|
|
||||||
|
class AccountCreating extends Event
|
||||||
|
{
|
||||||
|
public $request;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new event instance.
|
||||||
|
*
|
||||||
|
* @param $request
|
||||||
|
*/
|
||||||
|
public function __construct($request)
|
||||||
|
{
|
||||||
|
$this->request = $request;
|
||||||
|
}
|
||||||
|
}
|
20
app/Events/Banking/AccountDeleted.php
Normal file
20
app/Events/Banking/AccountDeleted.php
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Events\Banking;
|
||||||
|
|
||||||
|
use App\Abstracts\Event;
|
||||||
|
|
||||||
|
class AccountDeleted extends Event
|
||||||
|
{
|
||||||
|
public $account;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new event instance.
|
||||||
|
*
|
||||||
|
* @param $account
|
||||||
|
*/
|
||||||
|
public function __construct($account)
|
||||||
|
{
|
||||||
|
$this->account = $account;
|
||||||
|
}
|
||||||
|
}
|
20
app/Events/Banking/AccountDeleting.php
Normal file
20
app/Events/Banking/AccountDeleting.php
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Events\Banking;
|
||||||
|
|
||||||
|
use App\Abstracts\Event;
|
||||||
|
|
||||||
|
class AccountDeleting extends Event
|
||||||
|
{
|
||||||
|
public $account;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new event instance.
|
||||||
|
*
|
||||||
|
* @param $account
|
||||||
|
*/
|
||||||
|
public function __construct($account)
|
||||||
|
{
|
||||||
|
$this->account = $account;
|
||||||
|
}
|
||||||
|
}
|
25
app/Events/Banking/AccountUpdated.php
Normal file
25
app/Events/Banking/AccountUpdated.php
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Events\Banking;
|
||||||
|
|
||||||
|
use App\Abstracts\Event;
|
||||||
|
use App\Models\Banking\Account;
|
||||||
|
|
||||||
|
class AccountUpdated extends Event
|
||||||
|
{
|
||||||
|
public $account;
|
||||||
|
|
||||||
|
public $request;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new event instance.
|
||||||
|
*
|
||||||
|
* @param $account
|
||||||
|
* @param $request
|
||||||
|
*/
|
||||||
|
public function __construct(Account $account, $request)
|
||||||
|
{
|
||||||
|
$this->account = $account;
|
||||||
|
$this->request = $request;
|
||||||
|
}
|
||||||
|
}
|
25
app/Events/Banking/AccountUpdating.php
Normal file
25
app/Events/Banking/AccountUpdating.php
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Events\Banking;
|
||||||
|
|
||||||
|
use App\Abstracts\Event;
|
||||||
|
use App\Models\Banking\Account;
|
||||||
|
|
||||||
|
class AccountUpdating extends Event
|
||||||
|
{
|
||||||
|
public $account;
|
||||||
|
|
||||||
|
public $request;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new event instance.
|
||||||
|
*
|
||||||
|
* @param $account
|
||||||
|
* @param $request
|
||||||
|
*/
|
||||||
|
public function __construct(Account $account, $request)
|
||||||
|
{
|
||||||
|
$this->account = $account;
|
||||||
|
$this->request = $request;
|
||||||
|
}
|
||||||
|
}
|
@ -3,6 +3,8 @@
|
|||||||
namespace App\Jobs\Banking;
|
namespace App\Jobs\Banking;
|
||||||
|
|
||||||
use App\Abstracts\Job;
|
use App\Abstracts\Job;
|
||||||
|
use App\Events\Banking\AccountCreating;
|
||||||
|
use App\Events\Banking\AccountCreated;
|
||||||
use App\Interfaces\Job\HasOwner;
|
use App\Interfaces\Job\HasOwner;
|
||||||
use App\Interfaces\Job\HasSource;
|
use App\Interfaces\Job\HasSource;
|
||||||
use App\Interfaces\Job\ShouldCreate;
|
use App\Interfaces\Job\ShouldCreate;
|
||||||
@ -12,6 +14,8 @@ class CreateAccount extends Job implements HasOwner, HasSource, ShouldCreate
|
|||||||
{
|
{
|
||||||
public function handle(): Account
|
public function handle(): Account
|
||||||
{
|
{
|
||||||
|
event(new AccountCreating($this->request));
|
||||||
|
|
||||||
\DB::transaction(function () {
|
\DB::transaction(function () {
|
||||||
$this->model = Account::create($this->request->all());
|
$this->model = Account::create($this->request->all());
|
||||||
|
|
||||||
@ -22,6 +26,8 @@ class CreateAccount extends Job implements HasOwner, HasSource, ShouldCreate
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
event(new AccountCreated($this->model, $this->request));
|
||||||
|
|
||||||
return $this->model;
|
return $this->model;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,8 @@
|
|||||||
namespace App\Jobs\Banking;
|
namespace App\Jobs\Banking;
|
||||||
|
|
||||||
use App\Abstracts\Job;
|
use App\Abstracts\Job;
|
||||||
|
use App\Events\Banking\AccountDeleting;
|
||||||
|
use App\Events\Banking\AccountDeleted;
|
||||||
use App\Interfaces\Job\ShouldDelete;
|
use App\Interfaces\Job\ShouldDelete;
|
||||||
|
|
||||||
class DeleteAccount extends Job implements ShouldDelete
|
class DeleteAccount extends Job implements ShouldDelete
|
||||||
@ -11,10 +13,14 @@ class DeleteAccount extends Job implements ShouldDelete
|
|||||||
{
|
{
|
||||||
$this->authorize();
|
$this->authorize();
|
||||||
|
|
||||||
|
event(new AccountDeleting($this->model));
|
||||||
|
|
||||||
\DB::transaction(function () {
|
\DB::transaction(function () {
|
||||||
$this->model->delete();
|
$this->model->delete();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
event(new AccountDeleted($this->model));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,8 @@
|
|||||||
namespace App\Jobs\Banking;
|
namespace App\Jobs\Banking;
|
||||||
|
|
||||||
use App\Abstracts\Job;
|
use App\Abstracts\Job;
|
||||||
|
use App\Events\Banking\AccountUpdating;
|
||||||
|
use App\Events\Banking\AccountUpdated;
|
||||||
use App\Interfaces\Job\ShouldUpdate;
|
use App\Interfaces\Job\ShouldUpdate;
|
||||||
use App\Models\Banking\Account;
|
use App\Models\Banking\Account;
|
||||||
|
|
||||||
@ -12,6 +14,8 @@ class UpdateAccount extends Job implements ShouldUpdate
|
|||||||
{
|
{
|
||||||
$this->authorize();
|
$this->authorize();
|
||||||
|
|
||||||
|
event(new AccountUpdating($this->model, $this->request));
|
||||||
|
|
||||||
\DB::transaction(function () {
|
\DB::transaction(function () {
|
||||||
$this->model->update($this->request->all());
|
$this->model->update($this->request->all());
|
||||||
|
|
||||||
@ -22,6 +26,8 @@ class UpdateAccount extends Job implements ShouldUpdate
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
event(new AccountUpdated($this->model, $this->request));
|
||||||
|
|
||||||
return $this->model;
|
return $this->model;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user