user() ->notifications() ->orderBy('created_at', 'desc') ->paginate(15); return response()->json($notifications); } public function unreadCount(Request $request): JsonResponse { $count = $request->user() ->notifications() ->where('is_read', false) ->count(); return response()->json(['count' => $count]); } public function markAsRead(Request $request, AppNotification $notification): JsonResponse { if ($notification->user_id !== $request->user()->id) { return response()->json(['message' => 'Unauthorized'], 403); } $notification->update([ 'is_read' => true, 'read_at' => now(), ]); return response()->json(['message' => 'Notification marked as read.']); } public function destroy(Request $request, AppNotification $notification): JsonResponse { if ($notification->user_id !== $request->user()->id) { return response()->json(['message' => 'Unauthorized'], 403); } $notification->delete(); return response()->json(['message' => 'Notification deleted.']); } public function markAllAsRead(Request $request): JsonResponse { $request->user() ->notifications() ->where('is_read', false) ->update([ 'is_read' => true, 'read_at' => now(), ]); return response()->json(['message' => 'All notifications marked as read.']); } public function deleteAll(Request $request): JsonResponse { $request->user()->notifications()->delete(); return response()->json(['message' => 'All notifications deleted.']); } }