2019-11-16 10:21:14 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Jobs\Banking;
|
|
|
|
|
|
|
|
use App\Abstracts\Job;
|
2021-09-06 11:53:57 +03:00
|
|
|
use App\Interfaces\Job\HasOwner;
|
2021-09-07 10:33:34 +03:00
|
|
|
use App\Interfaces\Job\HasSource;
|
2021-09-06 11:53:57 +03:00
|
|
|
use App\Interfaces\Job\ShouldCreate;
|
2019-11-16 10:21:14 +03:00
|
|
|
use App\Models\Banking\Account;
|
|
|
|
|
2021-09-07 10:33:34 +03:00
|
|
|
class CreateAccount extends Job implements HasOwner, HasSource, ShouldCreate
|
2019-11-16 10:21:14 +03:00
|
|
|
{
|
2021-09-06 11:53:57 +03:00
|
|
|
public function handle(): Account
|
2019-11-16 10:21:14 +03:00
|
|
|
{
|
2020-06-26 13:40:19 +03:00
|
|
|
\DB::transaction(function () {
|
2021-09-06 11:53:57 +03:00
|
|
|
$this->model = Account::create($this->request->all());
|
2019-11-16 10:21:14 +03:00
|
|
|
|
2020-06-26 13:40:19 +03:00
|
|
|
// Set default account
|
|
|
|
if ($this->request['default_account']) {
|
2021-09-06 11:53:57 +03:00
|
|
|
setting()->set('default.account', $this->model->id);
|
2020-06-26 13:40:19 +03:00
|
|
|
setting()->save();
|
|
|
|
}
|
|
|
|
});
|
2019-11-16 10:21:14 +03:00
|
|
|
|
2021-09-06 11:53:57 +03:00
|
|
|
return $this->model;
|
2019-11-16 10:21:14 +03:00
|
|
|
}
|
|
|
|
}
|