summaryrefslogtreecommitdiff
path: root/src/Toolbar/Concerns/WithAction.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/Toolbar/Concerns/WithAction.php')
-rw-r--r--src/Toolbar/Concerns/WithAction.php33
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;
+ }
+}