From bd31d19c0e9dc5d066edc0ff42755ca2771a3763 Mon Sep 17 00:00:00 2001 From: "Ralph J. Smit" <59207045+ralphjsmit@users.noreply.github.com> Date: Mon, 12 May 2025 19:06:35 +0200 Subject: [PATCH] Update ViewComponent.php --- .../support/src/Components/ViewComponent.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/packages/support/src/Components/ViewComponent.php b/packages/support/src/Components/ViewComponent.php index c080cdaea7..f30d7c5b0f 100644 --- a/packages/support/src/Components/ViewComponent.php +++ b/packages/support/src/Components/ViewComponent.php @@ -101,6 +101,20 @@ abstract class ViewComponent extends Component implements Htmlable return $this->evaluate($this->defaultView); } + /** + * @return array + */ + public function getViewData(): array + { + return collect($this->viewData) + ->flatMap(function (mixed $value, string | int $key) { + return is_numeric($key) + ? $this->evaluate($value) + : [$key => $this->evaluate($value)]; + }) + ->all(); + } + public function toHtml(): string { return $this->render()->render(); @@ -114,7 +128,7 @@ abstract class ViewComponent extends Component implements Htmlable 'attributes' => new ComponentAttributeBag, ...$this->extractPublicMethods(), ...(isset($this->viewIdentifier) ? [$this->viewIdentifier => $this] : []), - ...$this->viewData, + ...$this->getViewData(), ], ); }