rowDecoration; $cellDecoration = $this->cellDecoration; $headers = $this->headers; // Remove closures from serialization unset($this->rowDecoration, $this->cellDecoration, $this->headers); // Serialize a unique ID for component tracking $this->uuid = "table-" . md5(serialize($this)) . $id; // Restore closures $this->rowDecoration = $rowDecoration; $this->cellDecoration = $cellDecoration; $this->headers = $headers; } // Check if header is hidden public function isHidden(mixed $header): bool { return $header['hidden'] ?? false; } // Format header contents public function format(mixed $row, mixed $field, mixed $header): mixed { $format = $header['format'] ?? null; if ( ! $format) { return $field; } if (is_callable($format)) { return $format($row, $field); } if ('currency' === $format[0]) { return ($format[2] ?? '') . number_format((float) $field, ...mb_str_split($format[1])); } if ('date' === $format[0] && $field) { return Carbon::parse($field)->translatedFormat($format[1]); } return $field; } // Check if link should be shown in cell public function hasLink(mixed $header): bool { return $this->link && empty($header['disableLink']); } // Build row link public function redirectLink(mixed $row): string { $link = $this->link; // Transform from `route()` pattern $link = Str::of($link)->replace('%5B', '{')->replace('%5D', '}'); // Extract tokens like {id}, {city.name} ... $tokens = Str::of($link)->matchAll('/\{(.*?)\}/'); // Replace tokens with actual row values $tokens->each(function (string $token) use ($row, &$link): void { $link = Str::of($link)->replace("{" . $token . "}", data_get($row, $token))->toString(); }); return $link; } public function rowClasses(mixed $row): ?string { $classes = []; foreach ($this->rowDecoration as $class => $condition) { if ($condition($row)) { $classes[] = $class; } } return Arr::join($classes, ' '); } public function cellClasses(mixed $row, array $header): ?string { $classes = Str::of($header['class'] ?? '')->explode(' ')->all(); foreach ($this->cellDecoration[$header['key']] ?? [] as $class => $condition) { if ($condition($row)) { $classes[] = $class; } } return Arr::join($classes, ' '); } public function render(): View|Closure|string { return <<<'HTML'
| {{ isset(${"header_".$temp_key}) ? ${"header_".$temp_key}($header) : $header['label'] }} | @endforeach @if($actions)Actions | @endif|
|---|---|---|
| $hasLink($header)])> @if($hasLink($header)) @endif {{ ${"cell_".$temp_key}($row) }} @if($hasLink($header)) @endif | @else$hasLink($header)])> @if($hasLink($header)) @endif {{ $format($row, data_get($row, $header['key']), $header) }} @if($hasLink($header)) @endif | @endif @endforeach @if($actions){{ $actions($row) }} | @endif