user(); return response()->json([ 'unread' => $user->unreadNotifications()->count(), 'items' => $user->notifications()->latest()->limit(20)->get()->map(fn (DatabaseNotification $notification): array => [ 'id' => $notification->id, 'kind' => $notification->data['kind'] ?? 'info', 'title' => $notification->data['title'] ?? '', 'body' => $notification->data['body'] ?? '', 'level' => $notification->data['level'] ?? 'info', 'url' => $notification->data['url'] ?? null, 'read' => $notification->read_at !== null, 'time' => $notification->created_at->diffForHumans(), ])->all(), ]); } public function read(Request $request, string $notification): JsonResponse { $request->user()->notifications()->whereKey($notification)->first()?->markAsRead(); return response()->json(['ok' => true]); } public function readAll(Request $request): JsonResponse { $request->user()->unreadNotifications->markAsRead(); return response()->json(['ok' => true]); } }