validate([ 'stem' => 'required|string', 'options' => 'nullable|array', 'answer' => 'nullable|string', 'solution' => 'nullable|string', ]); try { $service = app(ExamPdfExportService::class); // 过滤空选项 $options = array_filter($request->input('options', []), fn($v) => !empty($v)); $pdfPath = $service->generatePreviewPdf( stem: $request->input('stem'), options: $options, answer: $request->input('answer'), solution: $request->input('solution') ); // 返回可访问的 URL $url = Storage::disk('public')->url($pdfPath); return response()->json([ 'success' => true, 'url' => $url, ]); } catch (\Exception $e) { return response()->json([ 'success' => false, 'error' => $e->getMessage(), ], 500); } } }