Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Plugin Manager Laravel Package

fresns/plugin-manager

Laravel plugin manager for building modular, scalable apps. Treat each plugin as an independent mini-app with its own views, controllers, and models. Supports PHP 8+ and Laravel 9–13, with simple Composer install and optional config publishing.

View on GitHub
Deep Wiki
Context7
## Getting Started

### Minimal Steps to First Use
1. **Installation**
   ```bash
   composer require fresns/plugin-manager:^3.4.0
   php artisan vendor:publish --provider="Fresns\PluginManager\Providers\PluginServiceProvider"
  • Verify the config/plugin-manager.php file exists in your project.
  • Note: Ensure your Laravel version is 10.x or 11.x (v3.4.0 drops Laravel 9.x support).
  1. Create a Plugin Skeleton

    php artisan plugin:make my-first-plugin
    
    • This generates a plugin structure under plugins/MyFirstPlugin/ with:
      • routes/web.php (plugin-specific routes)
      • routes/api.php (API routes)
      • Providers/PluginServiceProvider.php (plugin bootstrapping)
      • views/ (Blade templates)
      • app/ (Models, Controllers, etc.)
    • New: Plugins now default to using Laravel 11.x conventions (e.g., app/Http/Controllers instead of app/Controllers).
  2. Register the Plugin

    • Add the plugin to config/plugin-manager.php under the plugins array:
      'plugins' => [
          'MyFirstPlugin' => [
              'enabled' => true,
              'path' => base_path('plugins/MyFirstPlugin'),
              'laravel_version' => '11.x', // Explicitly declare for compatibility
          ],
      ],
      
    • Run migrations (if applicable):
      php artisan plugin:migrate my-first-plugin
      
  3. First Use Case: Plugin Route

    • Define a route in plugins/MyFirstPlugin/routes/web.php:
      Route::get('/hello', function () {
          return 'Hello from MyFirstPlugin!';
      })->middleware('web'); // Explicit middleware declaration (L11+ best practice)
      
    • Access it at /hello (ensure the plugin is enabled).

Where to Look First

  • Documentation: https://pm.fresns.org (updated for Laravel 11.x).
  • Plugin Structure: Study the generated skeleton in plugins/ to understand isolation.
  • Configuration: config/plugin-manager.php for global settings (e.g., laravel_version compatibility flag).
  • Artisan Commands:
    • plugin:make (create new plugins, now defaults to L11+ structure).
    • plugin:enable/disable (toggle plugins).
    • plugin:migrate (run plugin migrations).
    • plugin:clear-cache (refresh plugin assets/routes).
    • New: plugin:check-compatibility (validates plugin against Laravel version).

Implementation Patterns

Core Workflows

1. Plugin Development Lifecycle

  • Isolation: Each plugin runs in its own namespace (e.g., MyFirstPlugin\Http\Controllers).
  • Bootstrapping: Override boot() in Providers/PluginServiceProvider.php for plugin-specific logic.
    public function boot()
    {
        // Laravel 11+ uses boot() for middleware/route model binding
        $this->routes();
        $this->loadViewsFrom(__DIR__.'/resources/views', 'plugins.my-first-plugin');
    }
    
  • Service Providers: Use PluginServiceProvider to bind plugin-specific services:
    public function register()
    {
        $this->app->singleton('my-plugin.service', function () {
            return new MyPluginService();
        });
    }
    

2. Routing and Middleware

  • Route Isolation: Plugin routes are loaded dynamically when the plugin is enabled.
    // plugins/MyFirstPlugin/routes/web.php
    Route::prefix('my-plugin')->middleware(['web', 'auth'])->group(function () {
        Route::get('/dashboard', [DashboardController::class, 'index']);
    });
    
  • Middleware: Apply plugin-specific middleware in PluginServiceProvider:
    public function boot()
    {
        $this->router->middlewareGroup('auth.my-plugin', [
            \App\Http\Middleware\Authenticate::class,
            \MyFirstPlugin\Http\Middleware\VerifyPluginRole::class,
        ]);
    }
    
  • Global Middleware: Add to config/plugin-manager.php:
    'middleware' => [
        'web' => ['auth.my-plugin'],
        'api' => ['throttle.my-plugin'],
    ],
    

3. Views and Assets

  • View Publishing: Use @include('plugins::my-first-plugin.view-name') in parent app views.
  • Asset Isolation: Publish plugin assets (CSS/JS) via:
    $this->publishes([
        __DIR__.'/public' => public_path('plugins/my-first-plugin'),
    ], 'public');
    
    New: Supports Laravel Mix/Vite integration:
    $this->mix(__DIR__.'/resources/js/app.js', 'plugins/my-first-plugin');
    
  • Blade Directives: Extend Blade with plugin-specific directives in PluginServiceProvider:
    Blade::directive('pluginAlert', function ($expression) {
        return "<?php echo Fresns\\PluginManager\\Blade::alert($expression); ?>";
    });
    

4. Database and Migrations

  • Schema Isolation: Each plugin has its own migrations directory (database/migrations).
  • Migration Execution:
    php artisan plugin:migrate my-first-plugin
    
  • Shared Database: Use Schema::connection('plugin_db') if configured in config/plugin-manager.php. New: Supports Laravel 11.x schema builder improvements:
    Schema::connection('plugin_db')->create('my_plugin_table', function (Blueprint $table) {
        $table->id();
        $table->timestamps();
        $table->foreignId('user_id')->constrained()->cascadeOnDelete();
    });
    

5. Event Handling

  • Plugin Events: Listen to plugin-specific events in PluginServiceProvider:
    public function boot()
    {
        event(new \MyFirstPlugin\Events\PluginEvent());
    }
    
  • Global Events: Subscribe to plugin lifecycle events (e.g., PluginEnabled, PluginDisabled) in your app’s EventServiceProvider. New: Supports Laravel 11.x event dispatching:
    event(new \MyFirstPlugin\Events\PluginUpdated());
    

6. Dependency Management

  • Plugin Dependencies: Define dependencies in config/plugin-manager.php:
    'plugins' => [
        'MyFirstPlugin' => [
            'dependencies' => ['AuthPlugin', 'DatabasePlugin'],
            'laravel_version' => '11.x',
        ],
    ],
    
  • Autoloading: Ensure plugin classes are autoloaded by adding them to composer.json:
    "autoload": {
        "psr-4": {
            "MyFirstPlugin\\": "plugins/MyFirstPlugin/src/"
        }
    }
    
    Then run composer dump-autoload.

Integration Tips

1. Parent App Integration

  • Service Binding: Bind plugin services to the container for use in the parent app:
    $this->app->bind('my-plugin.service', function () {
        return app('plugins.my-first-plugin')->service();
    });
    
  • Service Discovery: Use PluginManager::getPlugin('MyFirstPlugin') to access plugin instances. New: Supports Laravel 11.x container improvements:
    $plugin = app()->make(\Fresns\PluginManager\Contracts\Plugin::class, ['name' => 'MyFirstPlugin']);
    

2. Testing Plugins

  • Isolated Testing: Test plugins in isolation using PluginTestCase:
    use Fresns\PluginManager\Testing\PluginTestCase;
    
    class MyFirstPluginTest extends PluginTestCase
    {
        protected $plugin = 'MyFirstPlugin';
        protected $laravelVersion = '11.x'; // Explicitly declare
    
        public function test_plugin_route()
        {
            $this->get('/my-plugin/hello')
                 ->assertStatus(200)
                 ->assertSee('Hello from MyFirstPlugin!');
        }
    }
    
  • Mocking: Mock plugin dependencies in parent app tests:
    $this->mock(Fresns\PluginManager\Contracts\Plugin::class, function ($mock) {
        $mock->shouldReceive('isEnabled')->andReturn(true);
    });
    

3. Deployment Strategies

  • Plugin Updates: Use composer require for plugin updates, then run:
    php artisan plugin:update my-first-plugin
    
  • Zero-Downtime: Deploy plugins incrementally by:
    1. Enabling the new plugin version.
    2. Running migrations.
    3. Disabling the old version. New: Supports Laravel 11.x deployment presets
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed