validate([ 'title' => ['required', 'string', 'max:255'], 'description' => ['required', 'string'], 'severity' => ['required', 'in:low,medium,high'], 'reporter_email' => ['nullable', 'email', 'max:255'], 'attachment' => ['nullable', 'file', 'max:10240'], // 10MB ]); $attachmentPath = null; if ($request->hasFile('attachment')) { $attachmentPath = $request->file('attachment')->store('bug-reports', 'local'); } $issue = Issue::create([ 'title' => $validated['title'], 'description' => $validated['description'] . ($validated['reporter_email'] ? "\n\nReporter: {$validated['reporter_email']}" : ''), 'status' => Issue::STATUS_OPEN, 'priority' => $validated['severity'] === 'high' ? 'high' : ($validated['severity'] === 'medium' ? 'medium' : 'low'), 'created_by_id' => null, 'reviewer_id' => null, ]); // Attach beta label if exists; otherwise create a temporary one. $label = IssueLabel::firstOrCreate( ['name' => 'beta-feedback'], ['color' => '#7C3AED', 'description' => 'Feedback from beta testers'] ); $issue->labels()->syncWithoutDetaching([$label->id]); if ($attachmentPath) { $issue->attachments()->create([ 'file_path' => $attachmentPath, 'file_name' => $request->file('attachment')->getClientOriginalName(), 'file_size' => $request->file('attachment')->getSize(), 'uploaded_by_id' => null, ]); } return redirect() ->route('public.bug-report.create') ->with('status', '回報已送出,感謝協助!'); } }