F
Filament2mo ago
Jacob

Register plugin from service provider

Is it possible to register a plugin from the package's service provider? Instead of registering the plugin mannualy in the project's PanelProvider?
9 Replies
LeandroFerreira
LeandroFerreira2mo ago
you could try this in the AppServiceProvider
public function boot(): void
{
if ($currentPanel = filament()->getCurrentPanel()) {
$currentPanel->plugins([
XXPlugin::make(),
ZZPlugin::make(),
]);
}
}
public function boot(): void
{
if ($currentPanel = filament()->getCurrentPanel()) {
$currentPanel->plugins([
XXPlugin::make(),
ZZPlugin::make(),
]);
}
}
Jacob
JacobOP2mo ago
This does load the plugin, but I get some weird errors from plugins loaded by my plugin and widget blade files not loaded. It seems that it doesn't load any plugins and widgets from my package anymore, when I do it that way.
LeandroFerreira
LeandroFerreira2mo ago
Explain what you are trying to do
Jacob
JacobOP2mo ago
I have a Laravel composer package/ Filament plugin. When someone installs the package using composer I want that the Filament plugin is automatically loaded. So that the user doesn't have to add it manually to the ->plugins() in their AdminPanelProvider class.
LeandroFerreira
LeandroFerreira2mo ago
I think the configurability of a plugin depends on its purpose and functionality. For instance Spatie settings doesn't require panel specific configurations. Spatie translatable may need to adapt to different contexts depending on the panel it is associated.
Filament
Spatie Settings by Filament - Filament
Filament support for Spatie's Laravel Settings package.
Filament
Spatie Translatable by Filament - Filament
Filament support for Spatie's Laravel Translatable package.
Jacob
JacobOP2mo ago
Both packages don't have what I want. I simply want to load my Filament plugin without manualy registrering it in my AdminPanelProvider class.
flex
flex5d ago
@Jacob Did you find a way to "self-register" the plugins from the service providers? Trying this too but failing with: Route [filament.xxx.resources.posts.index] not defined.
Jacob
JacobOP3d ago
No, I did not find a way to do it. I’m pretty sure there is a way, but I didn’t had the time to dive into the Filament source code. @flex If you find a way to do it, please let me know!

Did you find this page helpful?