diff --git a/packages/panels/src/Commands/FileGenerators/Resources/Pages/ResourceManageRelatedRecordsPageClassGenerator.php b/packages/panels/src/Commands/FileGenerators/Resources/Pages/ResourceManageRelatedRecordsPageClassGenerator.php index 23d8a3c27d..a1b5e38c02 100644 --- a/packages/panels/src/Commands/FileGenerators/Resources/Pages/ResourceManageRelatedRecordsPageClassGenerator.php +++ b/packages/panels/src/Commands/FileGenerators/Resources/Pages/ResourceManageRelatedRecordsPageClassGenerator.php @@ -77,7 +77,6 @@ class ResourceManageRelatedRecordsPageClassGenerator extends ClassGenerator ? [$relatedResourceFqn] : [ Schema::class, - Table::class, ...($this->hasPartialImports() ? [ ...(blank($this->getTableFqn()) ? ['Filament\Actions', 'Filament\Tables'] : []), ...(blank($this->getFormSchemaFqn()) ? ['Filament\Forms'] : []), @@ -223,17 +222,32 @@ class ResourceManageRelatedRecordsPageClassGenerator extends ClassGenerator protected function addTableMethodToClass(ClassType $class): void { - if ($this->hasRelatedResource()) { + $relatedResource = $this->getRelatedResourceFqn(); + + if ($relatedResource && blank($headerActionsOutput = $this->outputTableHeaderActions())) { + // If the related resource is set and there are no table header actions to add, we don't need + // to generate the table method since it will be inherited from the related resource. return; } - $tableFqn = $this->getTableFqn(); + $this->namespace->addUse(Table::class); - $methodBody = filled($tableFqn) - ? <<headerActions([ + {$headerActionsOutput} + ]); + PHP; + } else { + $tableFqn = $this->getTableFqn(); + + $methodBody = filled($tableFqn) + ? <<simplifyFqn($tableFqn)}::configure(\$table); PHP - : $this->generateTableMethodBody($this->getRelatedModelFqn(), exceptColumns: Arr::wrap($this->getForeignKeyColumnToNotGenerate())); + : $this->generateTableMethodBody($this->getRelatedModelFqn(), exceptColumns: Arr::wrap($this->getForeignKeyColumnToNotGenerate())); + } $method = $class->addMethod('table') ->setPublic() diff --git a/packages/panels/src/Commands/FileGenerators/Resources/RelationManagerClassGenerator.php b/packages/panels/src/Commands/FileGenerators/Resources/RelationManagerClassGenerator.php index 3a1980dbe6..a5423f7c70 100644 --- a/packages/panels/src/Commands/FileGenerators/Resources/RelationManagerClassGenerator.php +++ b/packages/panels/src/Commands/FileGenerators/Resources/RelationManagerClassGenerator.php @@ -201,7 +201,8 @@ class RelationManagerClassGenerator extends ClassGenerator $relatedResource = $this->getRelatedResourceFqn(); if ($relatedResource && blank($headerActionsOutput = $this->outputTableHeaderActions())) { - // If the related resource is set and there are no table header actions, we don't need to generate the table method, since we + // If the related resource is set and there are no table header actions to add, we don't need + // to generate the table method since it will be inherited from the related resource. return; }