notifications() ->latest() ->limit(100) ->get() ->map(fn ($n) => $this->present($n)); $unread = $account->unreadNotifications()->count(); return response()->json([ 'data' => $notifications, 'unread_count' => $unread, ]); } public function unreadCount(Request $request): JsonResponse { $account = ladill_account(); return response()->json([ 'data' => [ 'unread_count' => $account->unreadNotifications()->count(), ], ]); } public function markAsRead(Request $request, string $id): JsonResponse { $notification = ladill_account() ->notifications() ->where('id', $id) ->first(); if ($notification) { $notification->markAsRead(); } return response()->json(['data' => ['success' => true]]); } public function markAllAsRead(Request $request): JsonResponse { ladill_account()->unreadNotifications->markAsRead(); return response()->json(['data' => ['success' => true]]); } /** @return array */ private function present(mixed $notification): array { return [ 'id' => $notification->id, 'type' => class_basename($notification->type), 'title' => $notification->data['title'] ?? 'Notification', 'message' => $notification->data['message'] ?? '', 'icon' => $notification->data['icon'] ?? 'bell', 'milestone' => $notification->data['milestone'] ?? null, 'url' => $notification->data['url'] ?? null, 'read_at' => $notification->read_at?->toIso8601String(), 'created_at' => $notification->created_at?->toIso8601String(), ]; } }