Skip to content

Commit

Permalink
Add company create and update events
Browse files Browse the repository at this point in the history
  • Loading branch information
burakcakirel committed Sep 13, 2020
1 parent c72b519 commit 0dfb759
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 0 deletions.
22 changes: 22 additions & 0 deletions app/Events/Common/CompanyCreated.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace App\Events\Common;

use Illuminate\Queue\SerializesModels;

class CompanyCreated
{
use SerializesModels;

public $company;

/**
* Create a new event instance.
*
* @param $company
*/
public function __construct($company)
{
$this->company = $company;
}
}
22 changes: 22 additions & 0 deletions app/Events/Common/CompanyCreating.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace App\Events\Common;

use Illuminate\Queue\SerializesModels;

class CompanyCreating
{
use SerializesModels;

public $request;

/**
* Create a new event instance.
*
* @param $request
*/
public function __construct($request)
{
$this->request = $request;
}
}
26 changes: 26 additions & 0 deletions app/Events/Common/CompanyUpdated.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace App\Events\Common;

use Illuminate\Queue\SerializesModels;

class CompanyUpdated
{
use SerializesModels;

public $company;

public $request;

/**
* Create a new event instance.
*
* @param $company
* @param $request
*/
public function __construct($company, $request)
{
$this->company = $company;
$this->request = $request;
}
}
26 changes: 26 additions & 0 deletions app/Events/Common/CompanyUpdating.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace App\Events\Common;

use Illuminate\Queue\SerializesModels;

class CompanyUpdating
{
use SerializesModels;

public $company;

public $request;

/**
* Create a new event instance.
*
* @param $company
* @param $request
*/
public function __construct($company, $request)
{
$this->company = $company;
$this->request = $request;
}
}
6 changes: 6 additions & 0 deletions app/Jobs/Common/CreateCompany.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -29,6 +31,8 @@ public function __construct($request)
*/
public function handle()
{
event(new CompanyCreating($this->request));

\DB::transaction(function () {
$this->company = Company::create($this->request->all());

Expand All @@ -41,6 +45,8 @@ public function handle()
$this->updateSettings();
});

event(new CompanyCreated($this->company));

return $this->company;
}

Expand Down
6 changes: 6 additions & 0 deletions app/Jobs/Common/UpdateCompany.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -35,6 +37,8 @@ public function handle()
{
$this->authorize();

event(new CompanyUpdating($this->company, $this->request));

\DB::transaction(function () {
$this->company->update($this->request->all());

Expand Down Expand Up @@ -77,6 +81,8 @@ public function handle()
setting()->forgetAll();
});

event(new CompanyUpdated($this->company, $this->request));

return $this->company;
}

Expand Down

0 comments on commit 0dfb759

Please sign in to comment.