add support for deleting service option

This commit is contained in:
Dane Everitt 2016-02-20 16:55:05 -05:00
parent 1e9bf1c220
commit dcfdb89e3c
4 changed files with 56 additions and 0 deletions

View file

@ -73,6 +73,28 @@ class Option
return $option->id;
}
public function delete($id)
{
$option = Models\ServiceOptions::findOrFail($id);
$servers = Models\Server::where('option', $option->id)->get();
if (count($servers) !== 0) {
throw new DisplayException('You cannot delete an option that has servers attached to it currently.');
}
DB::beginTransaction();
try {
Models\ServiceVariables::where('option_id', $option->id)->delete();
$option->delete();
DB::commit();
} catch (\Exception $ex) {
DB::rollBack();
throw $ex;
}
}
public function update($id, array $data)
{
$option = Models\ServiceOptions::findOrFail($id);