Conditionally hide relationship manager table based on the toggle value in the form

I can hide a specific input field or even the whole section in a form with something like: ->visible(fn (Get $get) => $get('is_swimmer') === true) for a User resource create/edit page - given the toggle field has ->live(). However, I don't know how to conditionally show a relation manager records (those I see under each form of a User record create/edit page) for only those users that have toggled the Is swimmer? field to true. Right now the table with additional stuff (as relationship manager table) is available for everybody. How to conditionally show this table only for is_swimmer === true and hide for those who are not swimmers - haven't toggled on the is_swimmer field.
2 Replies
Blackpig
Blackpig4mo ago
Try something like this in the RelationManager :
public static function canViewForRecord(Model $ownerRecord): bool
{
return $ownerRecord->is_swimmer == treu;
}
public static function canViewForRecord(Model $ownerRecord): bool
{
return $ownerRecord->is_swimmer == treu;
}
Wirkhof
Wirkhof4mo ago
Thanks, I have modified it to:
public static function canViewForRecord(Model $ownerRecord, string $pageClass): bool
{
return $ownerRecord->is_swimmer == true;
}
public static function canViewForRecord(Model $ownerRecord, string $pageClass): bool
{
return $ownerRecord->is_swimmer == true;
}
and it works with one slight issue. It's not real-time like the other fields in the form that change when I toggle. Here I have to save it and refresh the page to see the result. I mean it works. So, it's not a big issue. But if you or others know about something like ->live() for this situation, so the change is relfected in real-time when switching the toggle switch and not only after saving the record, it would be even better. Some kind of rerender of the whole page, perhaps?