F
Filamentβ€’13mo ago
Chriis

Modifying shared resources depending on the panel

Hello, I have two panels (one for admins and another for users), and I was wondering if it's possible to edit a resource (forms, tables, etc.) independently of the panel when it has been shared. For example, on the admin side, the resource has a field in its form to specify the team, but on the user side, this same resource shouldn't have this field since we are already within the context of a team (multi-tenancy). So is it possible in Filament and if so, how could I achieve that ? I've searched into the documentation but have found nothing on this particular point. Help would be really appreciated πŸ™‚
11 Replies
Saade
Saadeβ€’13mo ago
->visible(fn () => Filament::getCurrentPanel()->getId() === 'admin')
Chriis
ChriisOPβ€’13mo ago
Oh ok thx, but its really inconvenient if I have multiple of inputs to modify 🫀 @Saade
Saade
Saadeβ€’13mo ago
put them in a group if you can...
Chriis
ChriisOPβ€’13mo ago
Ok thx But there is absolutely no way of extending the resource class and like redefining the form and table ? It would be perfect
lazydog
lazydogβ€’13mo ago
@Chriis are you referring to the same use of resources? like in admin panel you have AddressResource and in user panel you still have AddressResource?
Chriis
ChriisOPβ€’13mo ago
Yes its exactly the same resource, records are going in the same database table, but the admin have some input that the user panel don't have because the admin panel is not in a tenant context I have already shared the resource like this in the user panel provider
->resources([SheetResource::class])
->resources([SheetResource::class])
lazydog
lazydogβ€’13mo ago
You can read this one https://filamentphp.com/docs/3.x/panels/resources/relation-managers#sharing-a-resources-form-and-table-with-a-relation-manager Or create a static function that returns an array of Forms or Table there you specify the fields for admin and fields for user panel
Chriis
ChriisOPβ€’13mo ago
Ok i'm going to look at that, thx. For the static function I dont really understand where I put the condition for "Admin panel OR User panel"
beachbound
beachboundβ€’12mo ago
Do you know of any examples out there that do this or are there any examples of this in the documentation? I tried doing this but ran into lots of problems with variables out of scope.
jackleblackdev
jackleblackdevβ€’12mo ago
anyone have a solution to redefine form and table .
DrByte
DrByteβ€’12mo ago
Solution: a trait, shared by multiple resources. Define your field definitions (eg: getNameField()) and column definitions in a trait that the Resources use, and build your forms/tables from an array of static function calls from the trait (eg: [MyTrait::getNameField(),etc]). This allows you to rearrange or be selective about which ones are included in any particular resource.
Want results from more Discord servers?
Add your server