diff --git a/packages/builder/src/Blocks/AbstractBlock.php b/packages/builder/src/Blocks/AbstractBlock.php index 7f12684ae..d6edbfc64 100644 --- a/packages/builder/src/Blocks/AbstractBlock.php +++ b/packages/builder/src/Blocks/AbstractBlock.php @@ -502,7 +502,15 @@ public function getDefaultSortDirection(): string public function getTableBulkActions(): array { - return $this->actions['bulk'] ?? []; + if (! isset($this->actions['bulk'])) { + return []; + } + + if (is_string($this->actions['bulk'])) { + return [$this->actions['bulk']]; + } + + return $this->actions['bulk']; } public function getTitle(): string @@ -537,7 +545,17 @@ protected function flattenArray(array $array): array public function getTableActions(): array { - return $this->getActions('resource'); + if (! isset($this->actions['resource'])) { + return []; + } + + // If it's a string (method call), wrap it in an array + if (is_string($this->actions['resource'])) { + return [$this->actions['resource']]; + } + + // If it's already an array, return as is + return $this->actions['resource']; } public function getPageActions(string $page): array diff --git a/packages/builder/src/Blocks/Features/SimpleType.php b/packages/builder/src/Blocks/Features/SimpleType.php index 189452848..47550c7c7 100644 --- a/packages/builder/src/Blocks/Features/SimpleType.php +++ b/packages/builder/src/Blocks/Features/SimpleType.php @@ -74,7 +74,7 @@ public function __construct( [ 'field' => 'type', 'operator' => '=', - 'value' => 'Article', + 'value' => $type, ], ], ], $this->enum), diff --git a/packages/builder/src/Blocks/Singles/Simple.php b/packages/builder/src/Blocks/Singles/Simple.php index 0b557143b..11b1e3ca9 100644 --- a/packages/builder/src/Blocks/Singles/Simple.php +++ b/packages/builder/src/Blocks/Singles/Simple.php @@ -30,12 +30,7 @@ public function __construct( 'static::getSimpleFormActions()', ]); - $this->actions['resource'] = [ - 'static::getSimpleResourceActions()', - ]; - - $this->actions['bulk'] = [ - 'static::getSimpleBulkActions()', - ]; + $this->actions['resource'] = 'static::getSimpleResourceActions()'; + $this->actions['bulk'] = 'static::getSimpleBulkActions()'; } } diff --git a/packages/builder/src/Generators/Entity/ResourceGenerator.php b/packages/builder/src/Generators/Entity/ResourceGenerator.php index bf521f6f1..413f700dc 100644 --- a/packages/builder/src/Generators/Entity/ResourceGenerator.php +++ b/packages/builder/src/Generators/Entity/ResourceGenerator.php @@ -256,11 +256,14 @@ protected function getTableActions(): string foreach ($this->getBlocks() as $block) { $blockActions = $block->getTableActions(); if (! empty($blockActions)) { - $actions = array_merge($actions, $blockActions); + if (is_string($blockActions) && str_contains($blockActions, 'static::')) { + return $blockActions; + } + $actions = array_merge($actions, (array) $blockActions); } } - return implode(",\n ", $actions); + return '['.implode(",\n ", $actions).']'; } protected function getTableFilters(): string @@ -283,12 +286,15 @@ protected function getTableBulkActions(): string if (method_exists($block, 'getTableBulkActions')) { $blockActions = $block->getTableBulkActions(); if (! empty($blockActions)) { - $actions = array_merge($actions, $blockActions); + if (is_string($blockActions) && str_contains($blockActions, 'static::')) { + return $blockActions; + } + $actions = array_merge($actions, (array) $blockActions); } } } - return implode(",\n ", $actions); + return '['.implode(",\n ", $actions).']'; } protected function getNavigationGroup(): string diff --git a/packages/builder/src/Templates/Entity/resource.php.stub b/packages/builder/src/Templates/Entity/resource.php.stub index 91f10ecca..80e5e1904 100644 --- a/packages/builder/src/Templates/Entity/resource.php.stub +++ b/packages/builder/src/Templates/Entity/resource.php.stub @@ -81,12 +81,8 @@ class {{ class_name }}Resource extends Resource {{ table_columns }} ]) ->defaultSort('{{ default_sort_column }}', '{{ default_sort_direction }}') - ->actions([ - {{ table_actions }} - ]) - ->bulkActions([ - {{ table_bulk_actions }} - ]) + ->actions({{ table_actions }}) + ->bulkActions({{ table_bulk_actions }}) ->filters([ {{ table_filters }} ]); diff --git a/packages/core/src/Traits/Tabs/TabsInResource.php b/packages/core/src/Traits/Tabs/TabsInResource.php index 7f816386e..e75444b92 100644 --- a/packages/core/src/Traits/Tabs/TabsInResource.php +++ b/packages/core/src/Traits/Tabs/TabsInResource.php @@ -27,25 +27,21 @@ public static function setCurrentTab(?string $tab): void protected static function applyTabQuery(Builder $query, string $currentTab): Builder { - // Skip if this is a soft-delete tab as it's already handled if (in_array($currentTab, ['trash', 'deleted'])) { return $query; } - // Get tab configuration $tabsConfig = config(static::getResourceKey().'.tabs', []); if (isset($tabsConfig[$currentTab]['query'])) { foreach ($tabsConfig[$currentTab]['query'] as $condition) { - $value = $condition['value']; - - // Handle closure values - if (is_string($value) && str_contains($value, 'function')) { - $value = eval("return {$value};"); + if (! isset($condition['field']) || ! isset($condition['operator'])) { + continue; } - // Apply configured query conditions - $query->where( + $value = $condition['value'] ?? null; + + $query = $query->where( $condition['field'], $condition['operator'], is_callable($value) ? $value() : $value @@ -58,10 +54,13 @@ protected static function applyTabQuery(Builder $query, string $currentTab): Bui protected static function getResourceKey(): string { - // Convert class name to config key - // e.g., App\Resources\UserResource -> 'user' $className = class_basename(static::class); + $key = strtolower(str_replace('Resource', '', $className)); + + if (str_contains(static::class, 'Builder\\Resources')) { + return 'previews.'.str_replace('_', '-', $key); + } - return strtolower(str_replace('Resource', '', $className)); + return $key; } }