mirror of
https://github.com/filamentphp/filament.git
synced 2026-09-24 15:42:09 +08:00
make tweaks to manage related records page generation in same way as RM
This commit is contained in:
+20
-6
@@ -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)
|
||||
? <<<PHP
|
||||
if ($relatedResource) {
|
||||
$methodBody = <<<PHP
|
||||
return \$table
|
||||
->headerActions([
|
||||
{$headerActionsOutput}
|
||||
]);
|
||||
PHP;
|
||||
} else {
|
||||
$tableFqn = $this->getTableFqn();
|
||||
|
||||
$methodBody = filled($tableFqn)
|
||||
? <<<PHP
|
||||
return {$this->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()
|
||||
|
||||
+2
-1
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user