Register Resources from a Plugin without adding it as Plugin in Panel?
Hi, in v2 I used PluginServiceProvider::$resources to register new resources. So, I just needed to install the package and the resource was available.
While upgrading to v3 I'm extending PackageServiceProvider now, but the resources don't get registered:
Is there any option to register resources in v3 from a plugin without the need to register it in the "parent" panel (as this is in a package for me too)?
Thank you!
23 Replies
One idea was to:
and seems like "something" is happening with the resource but is resulting into
have you create a plugin class?
https://github.com/filamentphp/plugin-skeleton/blob/3.x/src/SkeletonPlugin.php
GitHub
plugin-skeleton/src/SkeletonPlugin.php at 3.x · filamentphp/plugin-...
A package skeleton for developing Filament plugins. - filamentphp/plugin-skeleton
No, but if I create a Plugin, I need to explicitly load it in the panel or?
What, if the panel is created by another package and I don't know which plugins I will use later in this package?
Or can I use a plugin without the need of $panel->plugin() ?
for a plugin:
everyone using it has to register it in the panel provider
and all the resources in SkyPlugin will be available for them
if the panel is created by another package, I guess the user can extend it and add the plugin to it
then register it instead of the (package panel)
Yes, that's how I understand the new plugin development.
But may you have an idea for my scenario?
I have one "core" package which generates the panel with couple of resources, etc.. Everything is fine here. I plan to use this package in different laravel projects.
Now, for some, but not for all laravel projects I want to extend it by using the core-package PLUS a blog-package. Or maybe a shop-package or whatever. To extend the functionality. So panel provider is in a package too.
With v2 it worked really well. Installed the blog/shop package and register resources in their providers. And I hope that this is possible in v3 in any way too?
sorry, I don't understand your last sentence
(Is it an option to get the default panel from the blog provider and call plugin() on it?)
do you want blog/shop package in one panel?
they should extend the core's panel
there is only one panel
blog/shop just bring some resources, controllers, views, etc...
good then, it will work
I have multiple packages
I install them in one app
added it to the AdminPanelProvider
and they all there
your package only have to defiend the plugin class I mentioned it earlier and in it you can set the resources you want
but then the AdminPanelProvider need to be done in the laravel application? not in the core package?
thank you a lot btw, for taking time ❤️
yes
np 🙂
this my package
https://github.com/lara-zeus/sky/blob/3.x/src/SkyPlugin.php
and in my app
AdminPanelProvider
GitHub
sky/src/SkyPlugin.php at 3.x · lara-zeus/sky
CMS for your website. it include posts, pages, tags, and categories. with a frontend scaffolding ready to use - lara-zeus/sky
Hm, I hoped to continue the logic from v2. That I can "hook in" the resources from the blog package itself and don't need to make any adjustments somewhere else. This way I only had to composer install the package and functionality was fully ready. Would be great to avoid the panel provder in the laravel application to keep it as small as possible.
But seems to be difficult?
yes, I understand. But for now, I fortunately don't have the panel provider in the app. only in the core.
you have to created in the
panel provder
also it will be created when you install filament so.
and anyone using third party plugins have to register it in
->plugins([
But using panel provider in my "core" package works pretty well.. except for those blog plugin
I have the FilamentServiceProvider in my core package, not in the app
My app almost knows nothing about Filament. No composer reuqirements, no Filament resources, etc.. everything about Filament is in my core package.
And so far I just did this in my blog-package an evoila, PostResource was available in the Filament.
Didn't expect that it's so different in V3
did you register
FilamentServiceProvider
in the app?
in config/app.phpjust in the blog package's providers object
also you can ship entire plugin in a package maybe useful in your case
but it also requires your app to register the provider
https://filamentphp.com/docs/3.x/panels/plugins#distributing-a-panel-in-a-plugin
yes, thats what I am doing at the moment
core package delivers the panel
blog package should add resources to the core's panel 😛
may I can try to use getDefaultPanel() from the blog package's provder and then add the plugin()
ummm 🙂
I think you core have to use the blog in the provider
could work too
but then it wouldn't make sense to put blog code into own package. i try to put all the optional features into packages. blog and shop are just some example. and I don't want to force the projects to use the blog, etc..
but yeah, will try with getDefaultPanel(), didn't yet
I think this works in general and may is a good approach for some scenarios. Unfortunately I still get from somwhere in getNavigation() of panel. So panel defnitely take aware of the BlogPlugin. You know if I need to register any additional routes now? So far it was enough to register the resource and the resource contains all the pages in getPages().
`
not sure why, filament automatically registers the resource routes, so I think this means filament didnt register the posts resource routes for some reason!
hm hm...