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
->visible(fn () => Filament::getCurrentPanel()->getId() === 'admin')
Oh ok thx, but its really inconvenient if I have multiple of inputs to modify π«€ @Saade
put them in a group
if you can...
Ok thx
But there is absolutely no way of extending the resource class and like redefining the form and table ? It would be perfect
@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?
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
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
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"
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.
anyone have a solution to redefine form and table .
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.