Implement dark mode, bug report page, and schema dump
This commit is contained in:
66
app/Http/Controllers/PublicBugReportController.php
Normal file
66
app/Http/Controllers/PublicBugReportController.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?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', '回報已送出,感謝協助!');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user