diff options
author | Sam Light <samlight1994@gmail.com> | 2025-04-26 13:05:25 +0100 |
---|---|---|
committer | Sam Light <samlight1994@gmail.com> | 2025-04-26 13:05:25 +0100 |
commit | 6d26688fded015141a45a88b90b2d70a0ac88420 (patch) | |
tree | 33324531f6e9595c7eb190b89bcdb5a7b55d1b5f /src/Columns | |
parent | 88f71aeba1a1649661d713297d3a75454636b2d1 (diff) |
Larastanning
Diffstat (limited to 'src/Columns')
-rw-r--r-- | src/Columns/ButtonColumn.php | 2 | ||||
-rw-r--r-- | src/Columns/Column.php | 20 | ||||
-rw-r--r-- | src/Columns/ElementColumn.php | 5 |
3 files changed, 22 insertions, 5 deletions
diff --git a/src/Columns/ButtonColumn.php b/src/Columns/ButtonColumn.php index 794b175..2124a37 100644 --- a/src/Columns/ButtonColumn.php +++ b/src/Columns/ButtonColumn.php @@ -8,7 +8,7 @@ class ButtonColumn extends ElementColumn { protected string $element = 'button'; - protected function getElemAttributes(Model $row) : array + protected function getElemAttributes(Model $row): array { return parent::getElemAttributes($row) + [ 'type' => 'button' diff --git a/src/Columns/Column.php b/src/Columns/Column.php index 46a03ba..ad3a787 100644 --- a/src/Columns/Column.php +++ b/src/Columns/Column.php @@ -15,6 +15,10 @@ use Closure; class Column { use Makable; + + /** + * @var TableComponent<Model> + */ private TableComponent $table; private bool $showInSelect; private bool $shouldEscape = true; @@ -32,6 +36,10 @@ class Column { $this->showInSelect = $this->title !== null; } + /** + * @template TModel of Model + * @param TableComponent<TModel> $table + */ public function setTable(TableComponent $table): void { $this->table = $table; @@ -55,7 +63,9 @@ class Column { public function sortable(?callable $fn): static { - $this->sortFn = $fn; + if ($fn !== null) { + $this->sortFn = Closure::fromCallable($fn); + } return $this; } @@ -64,7 +74,11 @@ class Column { return $this->sortFn !== null; } - public function applySort(Builder $query, string $dir): void + /** + * @template TModel of Model + * @param Builder<TModel> $query + */ + public function applySort(Builder $query, ?string $dir): void { if ($this->sortFn !== null) { ($this->sortFn)($query, $dir); @@ -88,7 +102,7 @@ class Column { return $this; } - public function showInSelect($show = true): static + public function showInSelect(bool $show = true): static { $this->showInSelect = $show; return $this; diff --git a/src/Columns/ElementColumn.php b/src/Columns/ElementColumn.php index 71f0750..0e98d4a 100644 --- a/src/Columns/ElementColumn.php +++ b/src/Columns/ElementColumn.php @@ -20,7 +20,10 @@ abstract class ElementColumn extends Column return $this; } - protected function getElemAttributes(Model $row) : array + /** + * @return array<string, string> + */ + protected function getElemAttributes(Model $row): array { return $this->elemAttributesFn?->call($this, $row) ?? []; } |