@php
$faviconPath = public_path('favicon.ico'); // or change to 'favicon.png' if that's what you're using
$faviconUrl = asset('favicon.ico') . '?v=' . (file_exists($faviconPath) ? filemtime($faviconPath) : time());
@endphp
Report Table
Report
@php
function isListArray($arr) {
return array_keys($arr) === range(0, count($arr) - 1);
}
function renderTable($data) {
if (!is_array($data)) return "Invalid data";
if (isListArray($data)) {
$allKeys = [];
foreach ($data as $row) {
if (is_array($row)) {
foreach (array_keys($row) as $k) {
if (!in_array($k, $allKeys, true)) {
$allKeys[] = $k;
}
}
}
}
$html = "";
foreach ($allKeys as $key) {
$html .= "| " . e($key) . " | ";
}
$html .= "
";
foreach ($data as $row) {
$html .= "";
foreach ($allKeys as $key) {
$value = array_key_exists($key, $row) ? $row[$key] : null;
$html .= "| " . renderCell($value) . " | ";
}
$html .= "
";
}
$html .= "
";
return $html;
}
// Single object
$html = "";
foreach ($data as $key => $value) {
$html .= "| " . e($key) . " | " . renderCell($value) . " |
";
}
$html .= "
";
return $html;
}
function renderCell($value) {
if (is_array($value)) {
if (array_keys($value) === range(0, count($value) - 1)) {
if (empty($value)) return '[]';
if (is_string(reset($value))) {
return implode("
", array_map(function ($v) {
return "" . e($v) . "";
}, $value));
}
if (is_array(reset($value))) {
return "Nested Table:" . renderTable($value) . "
";
}
}
return renderTable($value);
}
if (is_bool($value)) return $value ? 'true' : 'false';
if (is_null($value)) return 'null';
return e((string)$value);
}
@endphp
{!! renderTable($data) !!}