Filament\PluginServiceProvider class provided by Filament:
PluginServiceProvider extends the service provider from Laravel Package Tools, so all configurePackage() options available there are available here as well.
Plugins must have a unique name property.
Registering plugins
Application plugins
If you’re developing a plugin for a specific application, you should register the new service provider in yourconfig/app.php file:
Distributed plugins
Much like a normal Laravel package, you should add your service provider’s fully qualified class name to theextra.laravel.providers array in your package’s composer.json file:
Resources
To register a custom resource, add the fully qualified class name to the$resources property in your service provider:
Resource and ensure that Livewire can discover it.
Pages
To register a custom page, add the fully qualified class name to the$pages property in your service provider:
Page and ensure that Livewire can discover it.
Widgets
To register a custom widget, add the fully qualified class name to the$widgets property in your service provider:
Widget and ensure that Livewire can discover it.
Frontend assets
Filament plugins can also register their own frontend assets. These assets will be included on all Filament related pages, allowing you to use your own CSS and JavaScript.Stylesheets
To include a custom stylesheet, add it to the$styles property in your service provider. You should use a unique name as the key and the URL to the stylesheet as the value.
Tailwind CSS
If you are using Tailwind classes, that are not used in Filament core, you need to compile your own Tailwind CSS file and bundle it with your plugin. Follow the Tailwind instructions for setup, but omit@tailwind base as this would overwrite the base styles if users customize their Filament theme.
After compilation, your Tailwind stylesheet may contain classes that are already used in Filament core. You should purge those classes with awcodes/filament-plugin-purge to keep the stylesheets size low.
Scripts
To include a custom script, add it to the$scripts property in your service provider. You should use a unique name as the key and the URL to the script as the value. These scripts will be added after the core Filament script.
$beforeCoreScripts property. This is useful if you want to hook into an Alpine event.
Providing data to the frontend
Whilst building your plugin, you might find the need to generate some data on the server and access it on the client. To do this, use thegetScriptData() method on your service provider and return an array of string keys and values that can be passed to converted into JSON:
User menu
To register user menu items from your plugin, return them from thegetUserMenuItems() method in your service provider:
Page and ensure that Livewire can discover it.
Commands, views, translations, migrations and more
Since thePluginServiceProvider extends the service provider from Laravel Package Tools, you can use the configurePackage method to register commands, views, translations, migrations and more.
ServingFilament Event
If you rely on data defined by Filament onboot() or through Filament::serving(), you can register listeners for the Filament\Events\ServingFilament event: