44 lines
1.0 KiB
PHP
44 lines
1.0 KiB
PHP
<?php
|
|
|
|
namespace App\Services\User;
|
|
|
|
use App\Models\Agency;
|
|
use App\Models\AgencyActivity;
|
|
use App\Services\SigdCrudService;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class AgencyService extends SigdCrudService
|
|
{
|
|
public function __construct(Agency $model)
|
|
{
|
|
parent::__construct($model);
|
|
}
|
|
|
|
public function updatePermissions(Agency $agency, array $permissions)
|
|
{
|
|
try {
|
|
DB::beginTransaction();
|
|
|
|
$agency->agencyActivity()->delete();
|
|
|
|
foreach ($permissions as $permission) {
|
|
list($sector, $code) = explode('|', $permission);
|
|
$dataForms = [
|
|
'agency_id' => $agency->id,
|
|
'form_sector' => $sector,
|
|
'form_code' => $code
|
|
];
|
|
|
|
$this->create($dataForms, AgencyActivity::class);
|
|
}
|
|
|
|
DB::commit();
|
|
|
|
return true;
|
|
} catch (\Exception $e) {
|
|
DB::rollBack();
|
|
throw $e;
|
|
}
|
|
}
|
|
}
|