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; } }
public function create($service, array $data) { $service = Models\Service::findOrFail($service); $validator = Validator::make($data, ['name' => 'required|string|max:255', 'description' => 'required|string|min:1', 'tag' => 'required|string|max:255', 'executable' => 'sometimes|string|max:255', 'docker_image' => 'required|string|max:255', 'startup' => 'sometimes|string']); if ($validator->fails()) { throw new DisplayValidationException($validator->errors()); } if (isset($data['executable']) && empty($data['executable'])) { $data['executable'] = null; } if (isset($data['startup']) && empty($data['startup'])) { $data['startup'] = null; } $option = new Models\ServiceOptions(); $option->parent_service = $service->id; $option->fill($data); $option->save(); return $option->id; }
public function newOption(Request $request, $service) { return view('admin.services.options.new', ['service' => Models\Service::findOrFail($service)]); }