osRepository->filter([ 'page' => $request->get('page') ?? 1 ], ['osGroup.host']); $title = 'List all Version OS'; return view('admin.package.version.index', compact('versions', 'title')); } public function create() { $title = 'Add new Version Os'; return view('admin.package.version.add', compact('title')); } public function store(OsVersionRequest $request) { $validatedData = $request->validated(); // Remove unnecessary fields unset($validatedData['vcenter_id'], $validatedData['module_datacenter_id']); DB::beginTransaction(); try { $this->osRepository->create($validatedData); DB::commit(); } catch (\Exception $error) { DB::rollBack(); return back()->withErrors($error->getMessage()); } return redirect()->route('package.version.index')->with('success', 'Add Os Version successfully'); } public function edit(int $id = 0) { $version = $this->osRepository->findWithRelationships($id, ['osGroup.host.datacenter.vCenter']); if (! $version) { return back()->withErrors('Can\'t find version os by ID #' . $id); } $title = "Edit version OS"; return view('admin.package.version.edit', compact('title', 'version')); } public function update(int $id = 0, OsVersionRequest $request) { $version = $this->osRepository->find($id); if (! $version) { return back()->withErrors('Can\'t find version os by ID #' . $id); } $validatedData = $request->validated(); // Remove unnecessary fields unset($validatedData['vcenter_id'], $validatedData['module_datacenter_id']); DB::beginTransaction(); try { $this->osRepository->update($id, $validatedData); DB::commit(); } catch (\Exception $error) { DB::rollBack(); return back()->withErrors($error->getMessage()); } return redirect()->route('package.version.index')->with('success', 'Update successfully'); } public function destroy(Request $request) { $validator = Validator::make($request->all(), [ 'oid' => 'numeric' ]); if ($validator->fails()) { return back()->withErrors($validator->getMessageBag()); } $version = Os::find($request->oid); if (! $version) { return back()->withErrors('Can\'t find version os by ID #' . $request->oid); } $version->delete(); return back()->with('success', 'Delete success'); } }