add ability to delete a service

This commit is contained in:
Dane Everitt 2016-02-20 16:23:04 -05:00
parent a50bb5da14
commit 177bd4ec9d
4 changed files with 54 additions and 0 deletions

View file

@ -85,4 +85,26 @@ class Service
$service->save();
}
public function delete($id)
{
$service = Models\Service::findOrFail($id);
$servers = Models\Server::where('service', $service->id)->get();
$options = Models\ServiceOptions::select('id')->where('parent_service', $service->id);
if (count($servers) !== 0) {
throw new DisplayException('You cannot delete a service that has servers associated with it.');
}
DB::beginTransaction();
try {
Models\ServiceVariables::whereIn('option_id', $options->get()->toArray())->delete();
$options->delete();
$service->delete();
DB::commit();
} catch (\Exception $ex) {
DB::rollBack();
throw $ex;
}
}
}