From 378bb6de99ba1142392854c9bddf2bad864a7973 Mon Sep 17 00:00:00 2001 From: Wietse van Ginkel Date: Fri, 28 Feb 2025 16:06:13 +0100 Subject: [PATCH 1/2] URL support for actions --- .../views/vendor/datatables/actions.blade.php | 17 +++++------ src/Action.php | 30 ++++++++----------- src/Livewire/DataTableComponent.php | 3 +- 3 files changed, 22 insertions(+), 28 deletions(-) diff --git a/resources/views/vendor/datatables/actions.blade.php b/resources/views/vendor/datatables/actions.blade.php index 4ebb2ac..387228e 100644 --- a/resources/views/vendor/datatables/actions.blade.php +++ b/resources/views/vendor/datatables/actions.blade.php @@ -1,12 +1,11 @@
- @foreach($actions as $action) - $value) - {{ $key }}="{{ $value }}" + @foreach($actions as $action) + $value) + {{ $key }}="{{ $value }}" + @endforeach> + {{ $action['label'] }} + @endforeach - > - {{ $action['label'] }} - - @endforeach
diff --git a/src/Action.php b/src/Action.php index 439c997..0a24dca 100644 --- a/src/Action.php +++ b/src/Action.php @@ -6,36 +6,30 @@ class Action { public string $name; public string $label; - public string $route; + public ?string $route; + public ?string $url; public array $attributes = []; /** * Action constructor. - * - * @param string $name Unique action name. - * @param string $label Button label. - * @param string $route Named route for the action. - * @param array $attributes Additional HTML attributes (e.g., classes, styles). */ - public function __construct(string $name, string $label, string $route, array $attributes = []) + public function __construct(string $name, string $label, ?string $route = null, ?string $url = null, array $attributes = []) { $this->name = $name; $this->label = $label; $this->route = $route; + $this->url = $url; $this->attributes = $attributes; } - /** - * Factory method to create an action instance. - * - * @param string $name Unique action name. - * @param string $label Button label. - * @param string $route Named route for the action. - * @param array $attributes Additional HTML attributes (e.g., classes, styles). - * @return self - */ - public static function make(string $name, string $label, string $route, array $attributes = []): self + public function toArray(): array { - return new self($name, $label, $route, $attributes); + return [ + 'name' => $this->name, + 'label' => $this->label, + 'route' => $this->route, + 'url' => $this->url, + 'attributes' => $this->attributes + ]; } } diff --git a/src/Livewire/DataTableComponent.php b/src/Livewire/DataTableComponent.php index 636aa8a..317189a 100644 --- a/src/Livewire/DataTableComponent.php +++ b/src/Livewire/DataTableComponent.php @@ -2,6 +2,7 @@ namespace Ginkelsoft\DataTables\Livewire; +use Ginkelsoft\DataTables\Action; use Livewire\Component; use Livewire\WithPagination; use Ginkelsoft\DataTables\Search; @@ -94,7 +95,7 @@ public function mount( { $this->model = $model; $this->columns = $columns; - $this->actions = $actions; + $this->actions = array_map(fn($action) => $action instanceof Action ? $action->toArray() : $action, $actions); $this->actionsView = $actionsView; $this->hiddenColumns = $hiddenColumns; $this->bulkActions = $bulkActions; From 90ec1e002fd87dc1288de1c9cbd5391e870fb16b Mon Sep 17 00:00:00 2001 From: Wietse van Ginkel Date: Fri, 28 Feb 2025 16:09:10 +0100 Subject: [PATCH 2/2] URL support for actions --- .../views/vendor/datatables/components/bulk-action.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/vendor/datatables/components/bulk-action.blade.php b/resources/views/vendor/datatables/components/bulk-action.blade.php index 63548a0..a39344b 100644 --- a/resources/views/vendor/datatables/components/bulk-action.blade.php +++ b/resources/views/vendor/datatables/components/bulk-action.blade.php @@ -1,7 +1,7 @@