Skip to main content

Introduction

The basis of Filament plugins are Laravel packages. They are installed into your Filament project via Composer, and follow all the standard techniques, like using service providers to register routes, views, and translations. If you’re new to Laravel package development, here are some resources that can help you grasp the core concepts: Filament plugins build on top of the concepts of Laravel packages and allow you to ship and consume reusable features for any Filament panel. They can be added to each panel one at a time, and are also configurable differently per-panel.

Configuring the panel with a plugin class

A plugin class is used to allow your package to interact with a panel configuration file. It’s a simple PHP class that implements the Plugin interface. 3 methods are required:
  • The getId() method returns the unique identifier of the plugin amongst other plugins. Please ensure that it is specific enough to not clash with other plugins that might be used in the same project.
  • The register() method allows you to use any configuration option that is available to the panel. This includes registering resources, custom pages, themes, render hooks and more.
  • The boot() method is run only when the panel that the plugin is being registered to is actually in-use. It is executed by a middleware class.
The users of your plugin can add it to a panel by instantiating the plugin class and passing it to the plugin() method of the configuration:

Fluently instantiating the plugin class

You may want to add a make() method to your plugin class to provide a fluent interface for your users to instantiate it. In addition, by using the container (app()) to instantiate the plugin object, it can be replaced with a different implementation at runtime:
Now, your users can use the make() method:

Configuring plugins per-panel

You may add other methods to your plugin class, which allow your users to configure it. We suggest that you add both a setter and a getter method for each option you provide. You should use a property to store the preference in the setter and retrieve it again in the getter:
Additionally, you can use the unique ID of the plugin to access any of its configuration options from outside the plugin class. To do this, pass the ID to the filament() method:
You may wish to have better type safety and IDE autocompletion when accessing configuration. It’s completely up to you how you choose to achieve this, but one idea could be adding a static method to the plugin class to retrieve it:
Now, you can access the plugin configuration using the new static method:

Distributing a panel in a plugin

It’s very easy to distribute an entire panel in a Laravel package. This way, a user can simply install your plugin and have an entirely new part of their app pre-built. When configuring a panel, the configuration class extends the PanelProvider class, and that is a standard Laravel service provider. You can use it as a service provider in your package:
You should then register it as a service provider in the composer.json of your package: