mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/izyim.git
synced 2026-08-25 07:23:57 +00:00
51 lines
1008 B
PHP
51 lines
1008 B
PHP
<?php
|
|
/**
|
|
* Created by PhpStorm.
|
|
* User: user
|
|
* Date: 30/04/2019
|
|
* Time: 2:29 PM
|
|
*/
|
|
|
|
namespace App\Classes\Modules\Companies\Services;
|
|
|
|
|
|
use App\Classes\Constants;
|
|
use App\Classes\Modules\Documents\DeleteAllDocuments;
|
|
use App\Models\Company;
|
|
use App\Http\Resources\Company as CompanyResource;
|
|
|
|
class DeletesCompany
|
|
{
|
|
|
|
/** @var Company */
|
|
private $repository;
|
|
|
|
/**
|
|
* DeletesCompany constructor.
|
|
* @param Company $repository
|
|
*/
|
|
public function __construct(Company $repository)
|
|
{
|
|
$this->repository = $repository;
|
|
}
|
|
|
|
|
|
public function execute(string $id)
|
|
{
|
|
|
|
$company = $this->repository->findOrFail($id);
|
|
|
|
|
|
foreach (Constants::COMPANY_DOCUMENTS as $documentType) {
|
|
(new DeleteAllDocuments(Constants::MODULE_TYPES['company'], $id, $documentType))->execute();
|
|
}
|
|
|
|
if ($company->delete()) {
|
|
|
|
// Return single compnay as a resource
|
|
return new CompanyResource($company);
|
|
|
|
}
|
|
}
|
|
|
|
} |