Files
usher-manage-stack/app/Http/Controllers/PublicBugReportController.php

67 lines
2.2 KiB
PHP

<?php
namespace App\Http\Controllers;
use App\Models\Issue;
use App\Models\IssueLabel;
use Illuminate\Http\Request;
class PublicBugReportController extends Controller
{
/**
* Show beta bug report form (public).
*/
public function create()
{
return view('public.bug-report');
}
/**
* Store a beta bug report as an Issue.
*/
public function store(Request $request)
{
$validated = $request->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', '回報已送出,感謝協助!');
}
}