get('cache/dashboard.blade.php'); if (!$cachedContent) { return response()->json([ 'status' => 'error', 'message' => 'Cached dashboard content not found.' ], 404); } // Regex pattern to extract icon, value, and label // Matches block-content, img src, font-size-h3 (value), and font-size-sm (label) $pattern = '/
]*>.*?
]*>(.*?)<\/div>/s'; preg_match_all($pattern, $cachedContent, $matches, PREG_SET_ORDER); $data = []; $baseUrl = url('/'); foreach ($matches as $match) { $iconPath = $match[1]; $value = trim(strip_tags($match[2])); $label = trim(strip_tags($match[3])); // Clean up excessive whitespace and newlines $value = preg_replace('/\s+/', ' ', $value); $label = preg_replace('/\s+/', ' ', $label); // Make the icon URL absolute $iconUrl = str_starts_with($iconPath, 'http') ? $iconPath : rtrim($baseUrl, '/') . '/' . ltrim($iconPath, '/'); if ($label) { $data[] = [ 'label' => $label, 'value' => $value, 'icon' => $iconUrl ]; } } return response()->json([ 'status' => 'success', 'data' => $data ]); } catch (\Exception $e) { return response()->json([ 'status' => 'error', 'message' => 'An error occurred while extracting dashboard data: ' . $e->getMessage() ], 500); } } }