F
Filamentericmp

Conditionally show relation manager

My items model, if a condition is met, will be able to have users or not. This condition can be calculated by retrieving the model and doing some simple checks on it. As i know which models can have users or not, i want to hide the users table in the edit page when they aren't able to have that relationship. any ideas how to achieve it?
public static function getRelations(): array
{
return [
RelationManagers\UsersRelationManager::class, // how to conditionally add this relation manager or not? i'd grab here the record and would do the checks
];
}
public static function getRelations(): array
{
return [
RelationManagers\UsersRelationManager::class, // how to conditionally add this relation manager or not? i'd grab here the record and would do the checks
];
}
Solution
S
sandofgods43d ago
you can find your answer here: https://filamentphp.com/docs/3.x/panels/resources/relation-managers#conditionally-showing-relation-managers You have to edit your RelationManager file and add the canViewForRecord function, and add your conditions inside.
E
ericmp42d ago
thank u!!! god didnt see that section