F
Filament15mo ago
Peet X

Reuse the same Resources in multiple panels

Hi everyone, I am building two panels; The first panel is for admin use and the second for staff members. In the admin panel I have access to all the data stored in my database, however the staff panel should only display the data related to the authenticated user. What is the best structure to follow as far as this scenario? There are several resources that I'd like to reuse in both panels but I should only filter the data on a admin/staff basis. Any suggestions? Thanks!
7 Replies
Peet X
Peet XOP15mo ago
@Patrick Boivin Hi, are you able to advice me on this one by any chance, please?
Patrick Boivin
Patrick Boivin15mo ago
Should be possible... are both panels without multi-tenancy?
Peet X
Peet XOP15mo ago
Yes, they are Ok so what I did instead, I am using a Trait in the two Resources created in the Admin and Staff pane;, in this way, there's going to be only one table/form implementation for both resources
Patrick Boivin
Patrick Boivin15mo ago
I don't think you need to duplicate the resources, you could configure them with panel discovery:
class AdminPanelProvider extends PanelProvider
{
public function panel(Panel $panel): Panel
{
return $panel
->discoverResources(in: app_path('Filament/Admin/Resources'), for: 'App\\Filament\\Admin\\Resources')
->discoverResources(in: app_path('Filament/Blog/Resources'), for: 'App\\Filament\\Blog\\Resources')
// ...
class AdminPanelProvider extends PanelProvider
{
public function panel(Panel $panel): Panel
{
return $panel
->discoverResources(in: app_path('Filament/Admin/Resources'), for: 'App\\Filament\\Admin\\Resources')
->discoverResources(in: app_path('Filament/Blog/Resources'), for: 'App\\Filament\\Blog\\Resources')
// ...
class BlogPanelProvider extends PanelProvider
{
public function panel(Panel $panel): Panel
{
return $panel
->discoverResources(in: app_path('Filament/Blog/Resources'), for: 'App\\Filament\\Blog\\Resources')
// ...
class BlogPanelProvider extends PanelProvider
{
public function panel(Panel $panel): Panel
{
return $panel
->discoverResources(in: app_path('Filament/Blog/Resources'), for: 'App\\Filament\\Blog\\Resources')
// ...
And use Filament::getCurrentPanel() to show/hide different things in the shared resources (Blog in my example)
Peet X
Peet XOP15mo ago
Thank you very much
Anik
Anik8mo ago
have you tried displaying different pages in the resource according to user?

Did you find this page helpful?