Merge pull request #1604 from burakcakirel/company-events
Add create and update events for company
This commit is contained in:
commit
bfef974afd
22
app/Events/Common/CompanyCreated.php
Normal file
22
app/Events/Common/CompanyCreated.php
Normal file
@ -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
app/Events/Common/CompanyCreating.php
Normal file
22
app/Events/Common/CompanyCreating.php
Normal file
@ -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
app/Events/Common/CompanyUpdated.php
Normal file
26
app/Events/Common/CompanyUpdated.php
Normal file
@ -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
app/Events/Common/CompanyUpdating.php
Normal file
26
app/Events/Common/CompanyUpdating.php
Normal file
@ -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;
|
||||||
|
}
|
||||||
|
}
|
@ -3,6 +3,8 @@
|
|||||||
namespace App\Jobs\Common;
|
namespace App\Jobs\Common;
|
||||||
|
|
||||||
use App\Abstracts\Job;
|
use App\Abstracts\Job;
|
||||||
|
use App\Events\Common\CompanyCreated;
|
||||||
|
use App\Events\Common\CompanyCreating;
|
||||||
use App\Models\Common\Company;
|
use App\Models\Common\Company;
|
||||||
use Artisan;
|
use Artisan;
|
||||||
|
|
||||||
@ -29,6 +31,8 @@ class CreateCompany extends Job
|
|||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
|
event(new CompanyCreating($this->request));
|
||||||
|
|
||||||
\DB::transaction(function () {
|
\DB::transaction(function () {
|
||||||
$this->company = Company::create($this->request->all());
|
$this->company = Company::create($this->request->all());
|
||||||
|
|
||||||
@ -41,6 +45,8 @@ class CreateCompany extends Job
|
|||||||
$this->updateSettings();
|
$this->updateSettings();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
event(new CompanyCreated($this->company));
|
||||||
|
|
||||||
return $this->company;
|
return $this->company;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,8 @@
|
|||||||
namespace App\Jobs\Common;
|
namespace App\Jobs\Common;
|
||||||
|
|
||||||
use App\Abstracts\Job;
|
use App\Abstracts\Job;
|
||||||
|
use App\Events\Common\CompanyUpdated;
|
||||||
|
use App\Events\Common\CompanyUpdating;
|
||||||
use App\Models\Common\Company;
|
use App\Models\Common\Company;
|
||||||
use App\Traits\Users;
|
use App\Traits\Users;
|
||||||
|
|
||||||
@ -35,6 +37,8 @@ class UpdateCompany extends Job
|
|||||||
{
|
{
|
||||||
$this->authorize();
|
$this->authorize();
|
||||||
|
|
||||||
|
event(new CompanyUpdating($this->company, $this->request));
|
||||||
|
|
||||||
\DB::transaction(function () {
|
\DB::transaction(function () {
|
||||||
$this->company->update($this->request->all());
|
$this->company->update($this->request->all());
|
||||||
|
|
||||||
@ -77,6 +81,8 @@ class UpdateCompany extends Job
|
|||||||
setting()->forgetAll();
|
setting()->forgetAll();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
event(new CompanyUpdated($this->company, $this->request));
|
||||||
|
|
||||||
return $this->company;
|
return $this->company;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user