PHPackages                             whilesmart/laravel-plugin-engine - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. whilesmart/laravel-plugin-engine

ActiveLibrary[Framework](/categories/framework)

whilesmart/laravel-plugin-engine
================================

A flexible plugin engine for Laravel applications

v1.1.0(3w ago)11.3k[6 issues](https://github.com/whilesmartphp/laravel-plugin-engine/issues)[1 PRs](https://github.com/whilesmartphp/laravel-plugin-engine/pulls)proprietaryPHPPHP ^8.1CI passing

Since Jun 19Pushed 3d agoCompare

[ Source](https://github.com/whilesmartphp/laravel-plugin-engine)[ Packagist](https://packagist.org/packages/whilesmart/laravel-plugin-engine)[ RSS](/packages/whilesmart-laravel-plugin-engine/feed)WikiDiscussions dev Synced yesterday

READMEChangelog (2)Dependencies (18)Versions (15)Used By (0)

Laravel Plugin Engine
=====================

[](#laravel-plugin-engine)

[![Tests](https://github.com/whilesmart/laravel-plugin-engine/actions/workflows/tests.yml/badge.svg?branch=main)](https://github.com/whilesmart/laravel-plugin-engine/actions/workflows/tests.yml)[![License: MIT](https://camo.githubusercontent.com/fdf2982b9f5d7489dcf44570e714e3a15fce6253e0cc6b5aa61a075aac2ff71b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e737667)](LICENSE)

A flexible and powerful plugin system for Laravel applications.

Features
--------

[](#features)

- Plugin discovery and registration
- Enable/disable plugins
- Plugin dependencies
- Console commands for plugin management
- Event-driven architecture
- Easy to extend

Installation
------------

[](#installation)

1. Install the package via Composer:

```
composer require whilesmart/laravel-plugin-engine
```

2. Publish the configuration file (optional):

```
php artisan vendor:publish --provider="WhileSmart\LaravelPluginEngine\Providers\PluginServiceProvider" --tag=config
```

Configuration
-------------

[](#configuration)

Publish the configuration file:

```
php artisan vendor:publish --provider="WhileSmart\LaravelPluginEngine\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

    'log_channel' => env('PLUGIN_ENGINE_LOG_CHANNEL'),       // Log channel, null = app default
    'log_level' => env('PLUGIN_ENGINE_LOG_LEVEL', 'warning'), // Minimum level the engine logs at
];
```

### Logging

[](#logging)

The engine logs through its own configurable channel and minimum level, independent of the application's logging:

- `PLUGIN_ENGINE_LOG_CHANNEL`: any channel from `config/logging.php`. Leave unset to use the application's default channel.
- `PLUGIN_ENGINE_LOG_LEVEL`: messages below this level are dropped. Defaults to `warning`, so routine discovery output stays out of production logs. Set to `debug` to trace plugin discovery and registration.

Usage
-----

[](#usage)

### Available Commands

[](#available-commands)

- `plugin:list` - List all available plugins
- `plugin:info {id}` - Show information about a plugin
- `plugin:enable {id}` - Enable a plugin
- `plugin:disable {id}` - Disable a plugin
- `plugin:install {package}` - Install a plugin
- `plugin:discover` - Discover and register all available plugins
- `plugin:cache` - Compile discovered plugins into a cache file
- `plugin:clear` - Remove the plugin cache file

### Caching

[](#caching)

By default, plugins are discovered by scanning the plugins directory and parsing each manifest on every boot. In production, compile the result to a cache file instead, alongside the framework's other caches:

```
php artisan plugin:cache
```

The compiled file is loaded on boot and the filesystem scan is skipped. Run this on every deploy, next to `config:cache` and `route:cache`. `plugin:enable`, `plugin:disable`, and `plugin:discover` refresh an existing cache automatically. To return to live discovery:

```
php artisan plugin:clear
```

### Creating a Plugin

[](#creating-a-plugin)

1. Create a new directory in the `plugins` directory (or your configured path)
2. 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"
    }
}
```

3. Create a service provider for your plugin:

```
