diff options
| author | Sam Light <samlight1994@gmail.com> | 2026-02-12 00:23:02 +0000 |
|---|---|---|
| committer | Sam Light <samlight1994@gmail.com> | 2026-02-12 00:23:02 +0000 |
| commit | 536fa6c917d63b14feeb8f876e6a1d62acb577fc (patch) | |
| tree | 548f6b23324c8a0ef9448d16773ffad33ccc9c0b /src/Toolbar/Concerns/WithAction.php | |
| parent | f998df6a2abaa211a730f247ce814f238228fb70 (diff) | |
Created new dropdown toolbar itemv2.1.0
Diffstat (limited to 'src/Toolbar/Concerns/WithAction.php')
| -rw-r--r-- | src/Toolbar/Concerns/WithAction.php | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/Toolbar/Concerns/WithAction.php b/src/Toolbar/Concerns/WithAction.php new file mode 100644 index 0000000..a1c33f2 --- /dev/null +++ b/src/Toolbar/Concerns/WithAction.php @@ -0,0 +1,33 @@ +<?php + +declare(strict_types=1); + +namespace Lightscale\LaralightTables\Toolbar\Concerns; + +trait WithAction +{ + protected ?string $action = null; + + /** + * @param string|array{0: string, ...<int, string|numeric|bool|null>} $action + */ + public function action(string|array $action): static + { + if (is_array($action)) { + $fn = array_shift($action); + $params = collect($action)->map( + fn ($v) => match (strtolower(gettype($v))) { + 'string' => "'{$v}'", + 'boolean' => $v ? 'true' : 'false', + 'null' => 'null', + default => (string) $v, + } + )->join(', '); + $this->action = "{$fn}({$params})"; + } else { + $this->action = $action; + } + + return $this; + } +} |
