RelationManager on View Resource

When i create a new relation manager and i add it in getRelations array then it automatically is shown on the edit page of my resource and there i can create,edit and delete from this. In the View page the table is shown but without being able to have actions. Is there a way so that i can have also on the View Page the same functionality of the Relation that i have in the Edit Page?
Solution:
@Nikos Koukos I think you need to override the isReadonly() method in the relation manager. https://filamentphp.com/docs/3.x/panels/resources/relation-managers#read-only-mode...
Jump to solution
6 Replies
Solution
ChesterS
ChesterS2mo ago
@Nikos Koukos I think you need to override the isReadonly() method in the relation manager. https://filamentphp.com/docs/3.x/panels/resources/relation-managers#read-only-mode
Nikos Koukos
Nikos Koukos2mo ago
Perfect @ChesterS this was exactly what i wanted thank you, and maybe you also know how to hide it from the Edit Page and Show it only on the View Page?
ChesterS
ChesterS2mo ago
I guess one way would be to use canViewForRecord and check the class https://filamentphp.com/docs/3.x/panels/resources/relation-managers#conditionally-showing-relation-managers eg
public static function canViewForRecord(User|Model $ownerRecord, string $pageClass): bool
{
return $pageClass == YourViewClass::class;
}
public static function canViewForRecord(User|Model $ownerRecord, string $pageClass): bool
{
return $pageClass == YourViewClass::class;
}
but I don't know if there's a better way
ChesterS
ChesterS2mo ago
¯\_(ツ)_/¯
Nikos Koukos
Nikos Koukos2mo ago
thank you very much this worked but need the page class as a string not as a class
public static function canViewForRecord(User|Model $ownerRecord, string $pageClass): bool
{
return $pageClass == 'App\Filament\Resources\MyResource\Pages\ViewMyResource';
}
public static function canViewForRecord(User|Model $ownerRecord, string $pageClass): bool
{
return $pageClass == 'App\Filament\Resources\MyResource\Pages\ViewMyResource';
}