Is it possible to share resources, pages and widgets across panels?

Since now we can have multiple panels, and each panel uses:
->discoverResources(in: app_path('Filament/Resources'), for: 'App\\Filament\\Resources')
->discoverPages(in: app_path('Filament/Pages'), for: 'App\\Filament\\Pages')
->discoverWidgets(in: app_path('Filament/Widgets'), for: 'App\\Filament\\Widgets')
->discoverResources(in: app_path('Filament/Resources'), for: 'App\\Filament\\Resources')
->discoverPages(in: app_path('Filament/Pages'), for: 'App\\Filament\\Pages')
->discoverWidgets(in: app_path('Filament/Widgets'), for: 'App\\Filament\\Widgets')
Is there a way to share resources among panels? Example: Sales & customer support should be able use SalesResource and OrdersWidget. If no such thing is possible. I'd like to collaborate on adding this feature.
17 Replies
Skrypt
Skrypt16mo ago
You can use –>resources(), ->pages() and ->widgets() to register custom resources/pages/widget for each panel.
SoraKeyheart
SoraKeyheartOP16mo ago
Is there any doc or code example you may kindly share?
Skrypt
Skrypt16mo ago
Dennis Koch
Dennis Koch16mo ago
I just put them in another folder "Shared" and register or extend from there
SoraKeyheart
SoraKeyheartOP16mo ago
by extend you mean I can add ->discoverResources() more than once?
Dennis Koch
Dennis Koch16mo ago
Extend as in Class inheritance.
Chriis
Chriis13mo ago
Hi @Dennis Koch is this possible to have more details about this (your last message) ?
Dennis Koch
Dennis Koch13mo ago
I have empty classes that extend source classes in a shared folder.
Chriis
Chriis13mo ago
Ok so for example in my "admin" panel I have a AdressResource with a form, table, etc. I want this resource also in my "app" panel, so I share it with the
->resources([AdressResource::class])
->resources([AdressResource::class])
However I want to have a different form in the "app" panel, so I can extend the resource for defining a new form, but with the same resource ?
Dennis Koch
Dennis Koch13mo ago
Yes, you could do it that way. Extend the base resource, overwrite the form and register the new Resource
Chriis
Chriis13mo ago
Oh ok, so it looks like that ?
namespace App\Filament\Resources;

class AdressResource extends Resource
{
// AdressResource form, table, etc ...
}
namespace App\Filament\Resources;

class AdressResource extends Resource
{
// AdressResource form, table, etc ...
}
namespace App\Filament\AppPanel\Resources;

class AppAdressResource extends AdressResource
{
// Overwriting the form, table, etc ... of the 'admin' panel AdressResource
}
namespace App\Filament\AppPanel\Resources;

class AppAdressResource extends AdressResource
{
// Overwriting the form, table, etc ... of the 'admin' panel AdressResource
}
And what do you mean by registering the new Resource ? If I register AppAdressResource as a new resource, the records are still going to go in the same database table than AdressResource ?
Dennis Koch
Dennis Koch13mo ago
Sure, they both use the same model
Chriis
Chriis13mo ago
Oh nice, it's perfect 🙂 Its a lot better than doing this, when you have mutilple changes
->visible(fn () => Filament::getCurrentPanel()->getId() === 'admin')
->visible(fn () => Filament::getCurrentPanel()->getId() === 'admin')
Thank you so much I created the AppFooResource extends FooResource but now I have two time the resource ... Probably because I have the one I share in the AppPanelProvider ->resources([]) and the one I create extending the FooResource class from the Admin panel 😦 And the resource in my admin panel is also impacted hmm ... Looks like there is no other option than ->visible
Dennis Koch
Dennis Koch13mo ago
Don't understand your setup. Shouldn't be an issue of you don't register both in the same panel
Chriis
Chriis13mo ago
I'm going to make a little diagram or something like that for better understanding and I will comeback to you 🙂
Chriis
Chriis13mo ago
@Dennis Koch Hi, here is the little schema for explaining what I try to do. Idk if it really helps 😅
No description
aurawindsurfing
aurawindsurfing12mo ago
@Dennis Koch great thread, simple but very powerful
Want results from more Discord servers?
Add your server