NB: This repository has been migrated to : https://github.com/whilesmart/laravel-plugin-engine
A flexible and powerful plugin system for Laravel applications.
- Plugin discovery and registration
- Enable/disable plugins
- Plugin dependencies
- Console commands for plugin management
- Event-driven architecture
- Easy to extend
- Install the package via Composer:
composer require trakli/plugin-engine
- Publish the configuration file (optional):
php artisan vendor:publish --provider="Trakli\PluginEngine\Providers\PluginServiceProvider" --tag=config
Edit the config/plugins.php
file to configure the plugin system:
return [
'path' => base_path('plugins'), // Path where plugins are stored
'namespace' => 'Plugins', // Root namespace for plugins
];
plugin:list
- List all available pluginsplugin:info {id}
- Show information about a pluginplugin:enable {id}
- Enable a pluginplugin:disable {id}
- Disable a pluginplugin:install {package}
- Install a pluginplugin:discover
- Discover and register all available plugins
- Create a new directory in the
plugins
directory (or your configured path) - Create a
plugin.json
file with the following structure:
{
"id": "example-plugin",
"name": "Example Plugin",
"description": "A sample plugin",
"version": "1.0.0",
"namespace": "Plugins\\Example",
"provider": "Plugins\\Example\\ExampleServiceProvider",
"enabled": true,
"requires": {
"php": ">=8.1",
"laravel/framework": "^10.0"
}
}
- Create a service provider for your plugin:
<?php
namespace Plugins\Example;
use Illuminate\Support\ServiceProvider;
class ExampleServiceProvider extends ServiceProvider
{
public function register()
{
// Register bindings
}
public function boot()
{
// Boot logic
$this->loadRoutesFrom(__DIR__.'/routes/web.php');
$this->loadViewsFrom(__DIR__.'/resources/views', 'example');
$this->loadMigrationsFrom(__DIR__.'/database/migrations');
}
}
plugins/
example-plugin/
src/
Http/
Controllers/
Models/
Providers/
ExampleServiceProvider.php
resources/
views/
routes/
web.php
database/
migrations/
plugin.json
README.md
The plugin system dispatches several events that you can listen for:
Trakli\PluginEngine\Events\PluginEnabling
- Fired before a plugin is enabledTrakli\PluginEngine\Events\PluginEnabled
- Fired after a plugin is enabledTrakli\PluginEngine\Events\PluginDisabling
- Fired before a plugin is disabledTrakli\PluginEngine\Events\PluginDisabled
- Fired after a plugin is disabledTrakli\PluginEngine\Events\PluginInstalled
- Fired after a plugin is installedTrakli\PluginEngine\Events\PluginDiscovered
- Fired when a plugin is discovered
This package is proprietary and confidential. All rights reserved.