json($hierarchyFtths); } catch (\Exception $e) { return response()->json([ 'message' => 'Failed to retrieve hierarchy FTTHs.', 'error' => $e->getMessage() ], 500); } } public function search(Request $request) { $payload = $request->all(); $dataBuilder = $this->setUpPayload($payload, 'm_hierarchy_ftth'); $builder = $dataBuilder['builder']; $countBuilder = $dataBuilder['count']; $dataGet = $builder->get(); $totalRecord = $countBuilder->count(); return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); } public function store(Request $request) { try { $attributes = $request->only(['name', 'parent_id', 'project_id']); $hierarchyFtth = HierarchyFtth::create($attributes); return response()->json([ 'message' => 'Hierarchy FTTH created successfully.', 'data' => $hierarchyFtth ]); } catch (\Exception $e) { return response()->json([ 'message' => 'Failed to create hierarchy FTTH.', 'error' => $e->getMessage() ], 500); } } public function show(HierarchyFtth $hierarchyFtth) { try { return response()->json($hierarchyFtth); } catch (\Exception $e) { return response()->json([ 'message' => 'Failed to retrieve hierarchy FTTH.', 'error' => $e->getMessage() ], 500); } } public function update(Request $request, HierarchyFtth $hierarchyFtth) { try { $hierarchyFtth->update($request->all()); return response()->json([ 'message' => 'Hierarchy FTTH updated successfully.', 'data' => $hierarchyFtth ]); } catch (\Exception $e) { return response()->json([ 'message' => 'Failed to update hierarchy FTTH.', 'error' => $e->getMessage() ], 500); } } public function destroy(HierarchyFtth $hierarchyFtth) { try { $hierarchyFtth->delete(); return response()->json([ 'message' => 'Hierarchy FTTH deleted successfully.', 'data' => $hierarchyFtth ]); } catch (\Exception $e) { return response()->json([ 'message' => 'Failed to delete hierarchy FTTH.', 'error' => $e->getMessage() ], 500); } } }