validate([ 'category' => 'required|string|in:general,ux,mobile,feature,complaint', 'overall_rating' => 'nullable|integer|min:1|max:5', 'ux_rating' => 'nullable|integer|min:1|max:5', 'comfort_rating' => 'nullable|integer|min:1|max:5', 'mobile_rating' => 'nullable|integer|min:1|max:5', 'uses_mobile' => 'nullable|boolean', 'nps_score' => 'nullable|integer|min:1|max:10', 'ux_comment' => 'nullable|string|max:2000', 'mobile_comment' => 'nullable|string|max:2000', 'feature_request' => 'nullable|string|max:2000', 'improvements' => 'nullable|string|max:2000', 'general_comment' => 'nullable|string|max:2000', ]); $data['user_id'] = auth()->id(); UserFeedback::create($data); return back()->with('success', 'Danke für dein Feedback!'); } // ── Admin ────────────────────────────────────────────────────────────── public function adminIndex(Request $request) { $status = $request->input('status', 'new'); $search = trim($request->input('search', '')); $query = UserFeedback::with('user') ->orderByDesc('created_at'); if ($status && $status !== 'all') { $query->where('status', $status); } if ($search !== '') { if (is_numeric($search)) { $query->where('id', (int) $search); } else { $query->whereHas('user', function ($q) use ($search) { $q->where('username', 'like', '%' . $search . '%'); }); } } $feedbacks = $query->paginate(25)->withQueryString(); $stats = [ 'total' => UserFeedback::count(), 'new' => UserFeedback::where('status', 'new')->count(), 'read' => UserFeedback::where('status', 'read')->count(), ]; return Inertia::render('Admin/Feedback', [ 'feedbacks' => $feedbacks, 'filters' => ['status' => $status, 'search' => $search], 'stats' => $stats, ]); } public function adminShow(int $id) { $feedback = UserFeedback::with('user')->findOrFail($id); if ($feedback->status === 'new') { $feedback->update(['status' => 'read']); } return Inertia::render('Admin/FeedbackShow', [ 'feedback' => $feedback, ]); } public function adminUpdate(Request $request, int $id) { $feedback = UserFeedback::findOrFail($id); $data = $request->validate([ 'status' => 'nullable|in:new,read', 'admin_note' => 'nullable|string|max:2000', ]); $feedback->update(array_filter($data, fn ($v) => $v !== null)); return back()->with('success', 'Gespeichert.'); } }