diff --git a/packages/support/src/Components/ViewComponent.php b/packages/support/src/Components/ViewComponent.php index f30d7c5b0f..f51aac9961 100644 --- a/packages/support/src/Components/ViewComponent.php +++ b/packages/support/src/Components/ViewComponent.php @@ -6,6 +6,7 @@ use Closure; use Exception; use Illuminate\Contracts\Support\Htmlable; use Illuminate\Contracts\View\View; +use Illuminate\Support\Arr; use Illuminate\View\ComponentAttributeBag; abstract class ViewComponent extends Component implements Htmlable @@ -21,7 +22,7 @@ abstract class ViewComponent extends Component implements Htmlable protected string | Closure | null $defaultView = null; /** - * @var array + * @var array */ protected array $viewData = []; @@ -65,7 +66,7 @@ abstract class ViewComponent extends Component implements Htmlable } /** - * @param array $data + * @param array $data */ public function viewData(array $data): static { @@ -102,17 +103,15 @@ abstract class ViewComponent extends Component implements Htmlable } /** - * @return array + * @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(); + return Arr::mapWithKeys($this->viewData, function (mixed $value, string | int $key) { + return is_numeric($key) + ? $this->evaluate($value) + : [$key => $this->evaluate($value)]; + }); } public function toHtml(): string