soysaltan/laravel-plugin-system
Composer 安装命令:
composer require soysaltan/laravel-plugin-system
包简介
A comprehensive Laravel plugin system with automatic registration of routes, controllers, services, views, and configs
关键字:
README 文档
README
An extensive Laravel plugin system that provides automatic registration of routes, controllers, services, views, and configurations for modular application development.
Features
- Automatic Plugin Discovery - Automatically scans and registers plugins
- ️ Route Registration - Auto-registers plugin routes with customizable prefixes
- Controller Binding - Automatically binds plugin controllers to the service container
- Service Registration - Registers services as singletons with interface binding support
- View Integration - Seamless integration with Laravel views and Livewire Volt
- ️ Config Management - Automatic configuration loading and merging
- Plugin Generator - Artisan command to create new plugins with boilerplate code
- Component Generator - Create commands, controllers, listeners, events, and views within plugins (v1.5)
- Component Management - Add components to existing plugins with duplicate detection (v1.5)
Installation
Install the package via Composer:
composer require soysaltan/laravel-plugin-system
Publish the configuration file:
php artisan vendor:publish --tag=laravel-plugin-system-config
Key Features (v1.5)
Smart Plugin Management
- Existing Plugin Detection: Automatically detects if a plugin already exists
- Component Addition: Add new components to existing plugins without recreation
- Duplicate Prevention: Warns and skips if component already exists
- Flexible Component Creation: Create individual or multiple components at once
Supported Components
- Commands: Custom Artisan commands with proper signatures
- Controllers: RESTful controllers with CRUD operations (extends Laravel Controller)
- Events: Broadcastable events with proper structure
- Listeners: Queue-enabled listeners with error handling
- Views: Blade templates or Livewire Volt components
- Routes: RESTful route definitions with proper namespacing (v1.5)
- Enums: PHP 8.1+ enums with string backing type
- Traits: Reusable trait classes (concerns) for shared functionality
- Providers: Service providers automatically created for each plugin
Configuration
The configuration file config/laravel-plugin-system.php allows you to customize:
return [ // Path where plugins are stored 'plugins_path' => app_path('Plugins'), // Base namespace for plugins 'plugin_namespace' => 'App\\Plugins', // Whether to prefix routes with 'plugins/' 'use_plugins_prefix_in_routes' => false, // Default view type for new plugins 'default_view_type' => 'volt', // 'volt' or 'blade' // Enable/disable Volt support 'enable_volt_support' => true, ];
Usage
Creating a Plugin
Use the Artisan command to create a new plugin:
# Create plugin with default view type (configured in config) php artisan make:plugin MyAwesomePlugin # Create plugin with Volt views php artisan make:plugin MyAwesomePlugin --view-type=volt # Create plugin with traditional Blade views php artisan make:plugin MyAwesomePlugin --view-type=blade # Auto-detect best view type based on configuration and availability php artisan make:plugin MyAwesomePlugin --view-type=auto
Creating Plugin Components (v1.5)
Generate specific components within your plugin:
# Create a command within the plugin php artisan make:plugin MyAwesomePlugin --command=ProcessDataCommand # Create a controller within the plugin php artisan make:plugin MyAwesomePlugin --controller=ApiController # Create an event within the plugin php artisan make:plugin MyAwesomePlugin --event=DataProcessedEvent # Create a listener within the plugin php artisan make:plugin MyAwesomePlugin --listener=SendNotificationListener # Create a view within the plugin php artisan make:plugin MyAwesomePlugin --view=dashboard # Create routes for the plugin (v1.5) php artisan make:plugin MyAwesomePlugin --route # Create an enum within the plugin php artisan make:plugin MyAwesomePlugin --enum=Status # Create a trait within the plugin php artisan make:plugin MyAwesomePlugin --trait=Cacheable # Combine multiple components php artisan make:plugin MyAwesomePlugin --command=ProcessCommand --controller=ProcessController --event=ProcessedEvent --enum=Status --trait=Cacheable --route
Adding Components to Existing Plugins (v1.5)
You can add new components to existing plugins without recreating them:
# Add a command to existing plugin php artisan make:plugin ExistingPlugin --command=NewCommand # Add multiple components to existing plugin php artisan make:plugin ExistingPlugin --controller=ApiController --event=UserRegistered --enum=Status --trait=Cacheable --route # If component already exists, it will be skipped with a warning php artisan make:plugin ExistingPlugin --command=ExistingCommand # Output: Command file 'ExistingCommand.php' already exists in plugin 'ExistingPlugin'. Skipping...
This creates the following structure:
app/Plugins/MyAwesomePlugin/
├── config.php # Plugin configuration
├── routes.php # Plugin routes
├── MyAwesomePluginProvider.php # Service provider (auto-created)
├── Controllers/
│ └── MyAwesomePluginController.php # Plugin controller
├── Services/
│ ├── MyAwesomePluginService.php # Plugin service
│ └── MyAwesomePluginServiceInterface.php # Service interface
├── Commands/ # Generated commands (v1.5)
│ └── ProcessDataCommand.php
├── Events/ # Generated events (v1.5)
│ └── DataProcessedEvent.php
├── Listeners/ # Generated listeners (v1.5)
│ └── SendNotificationListener.php
├── Status.php # Generated enum
├── Cacheable.php # Generated trait
└── Views/
└── index.blade.php # Livewire Volt component or Blade view
Plugin Structure
Config File (config.php)
<?php return [ 'name' => 'MyAwesomePlugin', 'version' => '1.0.0', 'description' => 'MyAwesomePlugin plugin', 'enabled' => true, ];
Routes File (routes.php)
<?php use Livewire\Volt\Volt; Volt::route('/', 'index');
Controller
<?php namespace App\Plugins\MyAwesomePlugin\Controllers; use App\Http\Controllers\Controller; class MyAwesomePluginController extends Controller { public function index() { // Controller logic } }
Service & Interface
<?php namespace App\Plugins\MyAwesomePlugin\Services; interface MyAwesomePluginServiceInterface { public function handle(): array; } class MyAwesomePluginService implements MyAwesomePluginServiceInterface { public function handle(): array { return [ 'message' => 'MyAwesomePlugin service is working!', 'timestamp' => now()->toISOString(), ]; } }
Service Provider
<?php namespace App\Plugins\MyAwesomePlugin; use Illuminate\Support\ServiceProvider; class MyAwesomePluginProvider extends ServiceProvider { public function register(): void { // Register plugin services here } public function boot(): void { // Boot plugin services here } }
Enum
<?php namespace App\Plugins\MyAwesomePlugin; enum Status: string { case ACTIVE = 'active'; case INACTIVE = 'inactive'; case PENDING = 'pending'; }
Trait
<?php namespace App\Plugins\MyAwesomePlugin; trait Cacheable { protected int $cacheTimeout = 3600; public function getCacheKey(string $suffix = ''): string { return static::class . ($suffix ? ":{$suffix}" : ''); } public function clearCache(string $suffix = ''): void { cache()->forget($this->getCacheKey($suffix)); } }
Views
The plugin system supports both Livewire Volt and traditional Blade views:
Volt Component (default):
<?php new class extends \Livewire\Volt\Component { public string $message = 'Welcome to MyAwesomePlugin Plugin!'; public function mount(): void { $this->message = 'Hello from MyAwesomePlugin!'; } } ?> <div class="p-6 bg-white rounded-lg shadow-md"> <h1 class="text-2xl font-bold text-gray-800 mb-4">MyAwesomePlugin Plugin</h1> <p class="text-gray-600 mb-4">{{ $message }}</p> </div>
Traditional Blade View:
@extends('layouts.app') @section('content') <div class="p-6 bg-white rounded-lg shadow-md"> <h1 class="text-2xl font-bold text-gray-800 mb-4">MyAwesomePlugin Plugin</h1> <p class="text-gray-600 mb-4">Welcome to MyAwesomePlugin Plugin!</p> <div class="bg-blue-50 border border-blue-200 rounded-lg p-4"> <h2 class="text-lg font-semibold text-blue-800 mb-2">Plugin Information</h2> <ul class="text-blue-700 space-y-1"> <li><strong>View Type:</strong> Traditional Blade</li> </ul> </div> </div> @endsection
Accessing Plugins
Once created, your plugin will be automatically registered and accessible via:
- Routes:
http://your-app.com/myawesomeplugin/(or/plugins/myawesomeplugin/if prefix is enabled) - Config:
config('MyAwesomePlugin.name') - Services: Injected via dependency injection or
app(MyAwesomePluginServiceInterface::class)
Service Injection
Plugin services are automatically registered and can be injected:
class SomeController extends Controller { public function __construct( private MyAwesomePluginServiceInterface $pluginService ) {} public function index() { $result = $this->pluginService->handle(); return response()->json($result); } }
Advanced Configuration
Custom Plugin Path
You can change the default plugin path in the configuration:
'plugins_path' => base_path('custom/plugins'),
Custom Namespace
Change the base namespace for plugins:
'plugin_namespace' => 'Custom\\Plugins',
Route Prefixing
Enable route prefixing to add 'plugins/' to all plugin routes:
'use_plugins_prefix_in_routes' => true,
Requirements
- PHP 8.1+
- Laravel 10.0+ or 11.0+
- Livewire Volt 1.0+ (for view components)
License
This package is open-sourced software licensed under the MIT license.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Support
If you discover any security vulnerabilities or bugs, please send an e-mail to soysaltan@hotmail.it
soysaltan/laravel-plugin-system 适用场景与选型建议
soysaltan/laravel-plugin-system 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 13 次下载、GitHub Stars 达 21, 最近一次更新时间为 2025 年 10 月 05 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「package」 「controllers」 「plugin」 「config」 「extensions」 「command」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 soysaltan/laravel-plugin-system 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 soysaltan/laravel-plugin-system 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 soysaltan/laravel-plugin-system 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
CakePHP 4.x AdminLTE Theme.
Opinionated Laravel Controllers extension
A package for generating annotations and drawing SwUi when working with Bitrix controllers.
Bullet development for Laravel Applications
Bundle of annotations to make it easier and faster to develop Rest APIs with Symfony.
统计信息
- 总下载量: 13
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 21
- 点击次数: 12
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-10-05