From d8d11445460a1a9e35c39937772d789036286fdf Mon Sep 17 00:00:00 2001 From: Sam Light Date: Mon, 6 Nov 2023 00:06:49 +0000 Subject: Made link column --- src/Columns/LinkColumn.php | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/Columns/LinkColumn.php (limited to 'src/Columns') diff --git a/src/Columns/LinkColumn.php b/src/Columns/LinkColumn.php new file mode 100644 index 0000000..7ba3a95 --- /dev/null +++ b/src/Columns/LinkColumn.php @@ -0,0 +1,38 @@ +urlFn = Closure::fromCallable($fn); + return $this; + } + + public function attributes(callable $fn) : static + { + $this->linkAttributesFn = $fn; + return $this; + } + + protected function getContent(Model $row) + { + $content = parent::getContent($row); + $url = $this->urlFn->call($this, $row); + $attributes = $this->linkAttributesFn?->call($this, $row) ?? []; + $attributes = (new ComponentAttributeBag(['href' => $url] + $attributes))->toHtml(); + + return new HtmlString("{$content}"); + } + +} -- cgit v1.2.3