make company current before deleting

This commit is contained in:
Denis Duliçi
2021-05-06 00:13:52 +03:00
parent 535da27d2e
commit 8e7dc3f119
3 changed files with 58 additions and 0 deletions

View File

@@ -3,6 +3,8 @@
namespace App\Jobs\Common;
use App\Abstracts\Job;
use App\Events\Common\CompanyDeleted;
use App\Events\Common\CompanyDeleting;
use App\Traits\Users;
class DeleteCompany extends Job
@@ -33,6 +35,10 @@ class DeleteCompany extends Job
{
$this->authorize();
$this->company->makeCurrent();
event(new CompanyDeleting($this->company, $this->current_company_id));
\DB::transaction(function () {
$this->deleteRelationships($this->company, [
'accounts', 'documents', 'document_histories', 'document_items', 'document_item_taxes', 'document_totals', 'categories',
@@ -45,6 +51,10 @@ class DeleteCompany extends Job
$this->company->delete();
});
event(new CompanyDeleted($this->company, $this->current_company_id));
company($this->current_company_id)->makeCurrent();
return true;
}