F
Filament2mo ago
Damien

Hide empty tables

When using relationship managers is there a way to make the table not render if there are no records. Thanks, Damien.
Solution:
like Dennis said, this doesn't make sense if you are using header actions to create or attach a record. Anyway, if you want to hide it, I think you can use getRelationManagers in your Edit or View page: ```php...
Jump to solution
3 Replies
Dennis Koch
Dennis Koch2mo ago
You'd still have an empty tab, right? Doesn't that look weird? You can overwrite public function getRelationManagers(): array to filter the relation manager, but I think that's confusing, too. For overwriting the actual rendering check getRelationManagersContentComponent() from HasRelationManagers trait.
Solution
LeandroFerreira
LeandroFerreira2mo ago
like Dennis said, this doesn't make sense if you are using header actions to create or attach a record. Anyway, if you want to hide it, I think you can use getRelationManagers in your Edit or View page:
public function getRelationManagers(): array
{
return $this->getRecord()
->yourRelationship()
->exists() ? [YourRelationManager::class] : [];
}
public function getRelationManagers(): array
{
return $this->getRecord()
->yourRelationship()
->exists() ? [YourRelationManager::class] : [];
}
Remove the relation manager class from getRelations method in the Resource
Damien
DamienOP2mo ago
Sorry, maybe I didn't explain it well, let's say for example I have users and addresses. I could have resources for both. I'd create the address in the address resource and the tab and table would only render for the user that has any addresses attached to them. Just to confirm though, this worked perfectly. Thank you

Did you find this page helpful?