Introduction
While Filament comes with virtually any tool youâll need to build great apps, sometimes youâll need to add your own functionality either for just your app or as redistributable packages that other developers can include in their own apps. This is why Filament offers a plugin system that allows you to extend its functionality. Before we dive in, itâs important to understand the different contexts in which plugins can be used. There are two main contexts:- Panel Plugins: These are plugins that are used with Panel Builders. They are typically used only to add functionality when used inside a Panel or as a complete Panel in and of itself. Examples of this are:
- A plugin that adds specific functionality to the dashboard in the form of Widgets.
- A plugin that adds a set of Resources / functionality to an app like a Blog or User Management feature.
- Standalone Plugins: These are plugins that are used in any context outside a Panel Builder. Examples of this are:
- A plugin that adds custom fields to be used with the Form Builders.
- A plugin that adds custom columns or filters to the Table Builders.
Important concepts
Before we dive into the specifics of building plugins, there are a few concepts that are important to understand. You should familiarize yourself with the following before building a plugin:The Plugin object
Filament introduces the concept of a Plugin object that is used to configure the plugin. This object is a simple PHP class that implements theFilament\Contracts\Plugin interface. This class is used to configure the plugin and is the main entry point for the plugin. It is also used to register Resources and Icons that might be used by your plugin.
While the plugin object is extremely helpful, it is not required to build a plugin. You can still build plugins without using the plugin object as you can see in the building a panel plugin tutorial.
The Plugin object is only used for Panel Providers. Standalone Plugins do not use this object. All configuration for Standalone Plugins should be handled in the pluginâs service provider.
Registering assets
Register assets shared by standalone components, including lazily loaded CSS, JavaScript, and Alpine components, in the plugin service providerâspackageBooted() method. For assets that should load on every page of a particular panel, use $panel->assets() in the plugin objectâs register() method. This avoids loading panel-specific assets in panels that do not use your plugin.