all(), [ 'level' => 'required|string|in:info,warning,error', 'message' => 'required|string', 'context' => 'nullable|array', ]); if ($validator->fails()) { return $this->errorResponse('Validation error', 422, $validator->errors()); } // 檢查機台是否存在 if (!Machine::where('id', $id)->exists()) { return $this->errorResponse('Machine not found', 404); } // 丟入隊列進行異步處理,回傳 202 Accepted ProcessMachineLog::dispatch($id, $request->only(['level', 'message', 'context'])); return $this->successResponse([], 'Log accepted. Processing asynchronously.', 202); } }