From 0dfb759ab0f45f7af785160260d91e2b334c3b1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20=C3=87ak=C4=B1rel?= Date: Sun, 13 Sep 2020 21:57:10 +0300 Subject: [PATCH] Add company create and update events --- app/Events/Common/CompanyCreated.php | 22 ++++++++++++++++++++++ app/Events/Common/CompanyCreating.php | 22 ++++++++++++++++++++++ app/Events/Common/CompanyUpdated.php | 26 ++++++++++++++++++++++++++ app/Events/Common/CompanyUpdating.php | 26 ++++++++++++++++++++++++++ app/Jobs/Common/CreateCompany.php | 6 ++++++ app/Jobs/Common/UpdateCompany.php | 6 ++++++ 6 files changed, 108 insertions(+) create mode 100644 app/Events/Common/CompanyCreated.php create mode 100644 app/Events/Common/CompanyCreating.php create mode 100644 app/Events/Common/CompanyUpdated.php create mode 100644 app/Events/Common/CompanyUpdating.php diff --git a/app/Events/Common/CompanyCreated.php b/app/Events/Common/CompanyCreated.php new file mode 100644 index 000000000..c6c6d87e5 --- /dev/null +++ b/app/Events/Common/CompanyCreated.php @@ -0,0 +1,22 @@ +company = $company; + } +} diff --git a/app/Events/Common/CompanyCreating.php b/app/Events/Common/CompanyCreating.php new file mode 100644 index 000000000..8bdbd8c14 --- /dev/null +++ b/app/Events/Common/CompanyCreating.php @@ -0,0 +1,22 @@ +request = $request; + } +} diff --git a/app/Events/Common/CompanyUpdated.php b/app/Events/Common/CompanyUpdated.php new file mode 100644 index 000000000..a5af45c4b --- /dev/null +++ b/app/Events/Common/CompanyUpdated.php @@ -0,0 +1,26 @@ +company = $company; + $this->request = $request; + } +} diff --git a/app/Events/Common/CompanyUpdating.php b/app/Events/Common/CompanyUpdating.php new file mode 100644 index 000000000..6146213a7 --- /dev/null +++ b/app/Events/Common/CompanyUpdating.php @@ -0,0 +1,26 @@ +company = $company; + $this->request = $request; + } +} diff --git a/app/Jobs/Common/CreateCompany.php b/app/Jobs/Common/CreateCompany.php index 339a05692..45b90d9fd 100644 --- a/app/Jobs/Common/CreateCompany.php +++ b/app/Jobs/Common/CreateCompany.php @@ -3,6 +3,8 @@ namespace App\Jobs\Common; use App\Abstracts\Job; +use App\Events\Common\CompanyCreated; +use App\Events\Common\CompanyCreating; use App\Models\Common\Company; use Artisan; @@ -29,6 +31,8 @@ class CreateCompany extends Job */ public function handle() { + event(new CompanyCreating($this->request)); + \DB::transaction(function () { $this->company = Company::create($this->request->all()); @@ -41,6 +45,8 @@ class CreateCompany extends Job $this->updateSettings(); }); + event(new CompanyCreated($this->company)); + return $this->company; } diff --git a/app/Jobs/Common/UpdateCompany.php b/app/Jobs/Common/UpdateCompany.php index 06301c110..517eb7fad 100644 --- a/app/Jobs/Common/UpdateCompany.php +++ b/app/Jobs/Common/UpdateCompany.php @@ -3,6 +3,8 @@ namespace App\Jobs\Common; use App\Abstracts\Job; +use App\Events\Common\CompanyUpdated; +use App\Events\Common\CompanyUpdating; use App\Models\Common\Company; use App\Traits\Users; @@ -35,6 +37,8 @@ class UpdateCompany extends Job { $this->authorize(); + event(new CompanyUpdating($this->company, $this->request)); + \DB::transaction(function () { $this->company->update($this->request->all()); @@ -77,6 +81,8 @@ class UpdateCompany extends Job setting()->forgetAll(); }); + event(new CompanyUpdated($this->company, $this->request)); + return $this->company; }