v2 first commit
This commit is contained in:
60
app/Jobs/Common/DeleteCompany.php
Normal file
60
app/Jobs/Common/DeleteCompany.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs\Common;
|
||||
|
||||
use App\Abstracts\Job;
|
||||
use App\Models\Common\Company;
|
||||
use App\Traits\Users;
|
||||
|
||||
class DeleteCompany extends Job
|
||||
{
|
||||
use Users;
|
||||
|
||||
protected $company;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @param $request
|
||||
*/
|
||||
public function __construct($company)
|
||||
{
|
||||
$this->company = $company;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return Company
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->authorize();
|
||||
|
||||
$this->company->delete();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if this action is applicable.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
// Can't delete active company
|
||||
if ($this->company->id == session('company_id')) {
|
||||
$message = trans('companies.error.delete_active');
|
||||
|
||||
throw new \Exception($message);
|
||||
}
|
||||
|
||||
// Check if user can access company
|
||||
if (!$this->isUserCompany($this->company->id)) {
|
||||
$message = trans('companies.error.not_user_company');
|
||||
|
||||
throw new \Exception($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user