summaryrefslogtreecommitdiff
path: root/src/Columns/LinkColumn.php
blob: ee974df36a58d1348ce45549cd9c5cc73a10a335 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?php

namespace Lightscale\LaralightTables\Columns;

use Closure;
use Illuminate\Database\Eloquent\Model;

class LinkColumn extends ElementColumn
{
    protected string $element = 'a';

    /**
     * @var Closure(Model): string
     */
    private Closure $urlFn;

    public function url(callable $fn): static
    {
        $this->urlFn = Closure::fromCallable($fn);

        return $this;
    }

    public function getElemAttributes(Model $row): array
    {
        return parent::getElemAttributes($row) + [
            'href' => ($this->urlFn)($row),
        ];
    }
}