get('per_page', 15), 500); $filter = $request->get('filter'); $status = $request->get('status'); $customerId = $request->get('customer_id'); $query = $this->accounts->model ->with(self::RELATIONSHIPS) ->newQuery(); if ($filter) { $query->where(function ($sub) use ($filter) { $sub->where('hosting_plan', 'like', "%{$filter}%") ->orWhere('ftp_username', 'like', "%{$filter}%") ->orWhere('system_username', 'like', "%{$filter}%"); }); } if ($status !== null && $status !== '') { $query->where('status', $status); } if ($customerId) { $query->where('customer_id', $customerId); } $paginator = $query->orderByDesc('id')->paginate($perPage); return response()->json([ 'error' => false, 'data' => [ 'items' => HostingAccountResource::collection($paginator->getCollection()), 'total' => $paginator->total(), 'per_page' => $paginator->perPage(), 'current_page' => $paginator->currentPage(), 'last_page' => $paginator->lastPage(), ], ]); } public function show(int $id): JsonResponse { $account = $this->accounts->model->with(self::RELATIONSHIPS)->find($id); if (!$account) { return response()->json(['error' => true, 'message' => "Không tìm thấy hosting account #$id"], 404); } return response()->json(['error' => false, 'data' => new HostingAccountResource($account)]); } public function store(CreateHostingAccountRequest $request): JsonResponse { $result = $this->pleskHostingService->provision($request->validated()); if ($result['error']) { return response()->json([ 'error' => true, 'message' => $result['message'] ?? 'Không thể tạo hosting account trên Plesk', ], 422); } $account = $result['data']->load(self::RELATIONSHIPS); return response()->json([ 'error' => false, 'data' => new HostingAccountResource($account), // Not persisted anywhere — this response is the only place it's ever shown. 'ftp_password' => $result['ftp_password'], ], 201); } public function update(int $id, UpdateHostingAccountRequest $request): JsonResponse { $account = $this->accounts->find($id); if (!$account) { return response()->json(['error' => true, 'message' => "Không tìm thấy hosting account #$id"], 404); } $this->accounts->update($id, $request->validated()); return $this->show($id); } public function destroy(int $id): JsonResponse { $account = $this->accounts->find($id); if (!$account) { return response()->json(['error' => true, 'message' => "Không tìm thấy hosting account #$id"], 404); } // Local record only — does not deprovision the subscription on Plesk, // same as DnsManager\DomainController::destroy leaving the Plesk side alone. $this->accounts->delete($id); return response()->json(['error' => false, 'message' => 'Đã xoá hosting account']); } public function suspend(int $id): JsonResponse { return $this->notImplemented(); } public function unsuspend(int $id): JsonResponse { return $this->notImplemented(); } public function resetFtpPassword(int $id): JsonResponse { return $this->notImplemented(); } private function notImplemented(): JsonResponse { return response()->json([ 'error' => true, 'message' => 'Not implemented in this phase', ], 501); } }