update
This commit is contained in:
@@ -93,6 +93,43 @@ class VCenterController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
public function storeNode(Request $request, string $type): JsonResponse
|
||||
{
|
||||
$rules = match ($type) {
|
||||
'datacenter' => [
|
||||
'vcenter_id' => 'required|integer|exists:module_vcenter,id',
|
||||
'name' => 'required|string|max:255',
|
||||
'datacenter_id' => 'nullable|string|max:255',
|
||||
],
|
||||
'host' => [
|
||||
'module_datacenter_id' => 'required|integer|exists:module_datacenter,id',
|
||||
'name' => 'required|string|max:255',
|
||||
'host_id' => 'nullable|string|max:255',
|
||||
'template' => 'nullable|string|max:500',
|
||||
'console' => 'nullable|string|max:500',
|
||||
'iso_path' => 'nullable|string|max:500',
|
||||
],
|
||||
'network' => [
|
||||
'module_host_id' => 'required|integer|exists:module_host,id',
|
||||
'name' => 'required|string|max:255',
|
||||
'network' => 'nullable|string|max:255',
|
||||
'type' => 'nullable|string|max:255',
|
||||
],
|
||||
default => abort(422, 'Không hỗ trợ tạo node loại này'),
|
||||
};
|
||||
|
||||
$data = $request->validate($rules);
|
||||
$data['status'] = 1;
|
||||
|
||||
$model = match ($type) {
|
||||
'datacenter' => ModuleDatacenter::create($data),
|
||||
'host' => ModuleHost::create($data),
|
||||
'network' => ModuleNetwork::create($data),
|
||||
};
|
||||
|
||||
return response()->json(['error' => false, 'data' => $model], 201);
|
||||
}
|
||||
|
||||
public function updateNode(Request $request, string $type, int $id): JsonResponse
|
||||
{
|
||||
$model = $this->resolveModel($type, $id);
|
||||
|
||||
Reference in New Issue
Block a user