Installation:
composer require codeages/plugin-bundle
php artisan vendor:publish --provider="Codeages\PluginBundle\PluginBundleServiceProvider"
Create a Plugin Skeleton:
plugins/DemoPlugin/ structure from the README.plugin.json with metadata (e.g., code, name, version).PluginBase in DemoPlugin.php.First Use Case:
php artisan plugin:register Demo
plugins table in the database or running:
php artisan plugin:list
Plugin Lifecycle Management:
plugin:register to enable a plugin. Triggers onInstall() in PluginBase.plugin:remove to disable. Triggers onUninstall().plugin:enable/plugin:disable for runtime toggling (hooks onEnable()/onDisable()).Service Integration:
DemoPlugin.php:
protected function register()
{
$this->app->bind('DemoService', function ($app) {
return new \DemoPlugin\Service\DemoService();
});
}
DemoPlugin.php:
protected function boot()
{
Route::prefix('demo')->group(function () {
Route::get('/', 'Controller@index');
});
}
Database Migrations:
Migrations/ and run:
php artisan plugin:migrate Demo
php artisan plugin:migrate:rollback Demo
Asset Management:
Resources/ for views, JS, or CSS.DemoPlugin.php:
View::addNamespace('demo', __DIR__.'/Resources/views');
Event Handling:
PluginRegistered):
$this->app->booting(function () {
event(new \Codeages\PluginBundle\Events\PluginRegistered($this));
});
Namespace Collisions:
\DemoPlugin\Service\DemoService).Migration Conflicts:
Schema::table() for altering existing tables to avoid conflicts.plugin:migrate twice may fail if migrations aren’t idempotent. Use --force cautiously:
php artisan plugin:migrate Demo --force
Service Provider Order:
plugin.json "code". Prepend codes (e.g., A_Demo) to enforce priority.Caching Issues:
php artisan config:clear
php artisan cache:clear
Debugging:
php artisan plugin:status Demo
onInstall()/onEnable() to diagnose failures.Custom Commands:
$this->commands([
\DemoPlugin\Console\CustomCommand::class,
]);
DemoPlugin.php.Plugin Hooks:
PluginBase:
public function onInstall()
{
// Custom logic (e.g., seed data)
}
Dynamic Configuration:
config() in PluginBase to merge settings:
$this->mergeConfigFrom(__DIR__.'/Config/demo.php', 'demo');
Multi-Tenancy:
plugins_demo table with a tenant_id column.$this->app->bind('tenant', function () {
return Tenant::findOrFail(request()->tenant_id);
});
Testing:
PluginManager:
$pluginManager = \Mockery::mock(\Codeages\PluginBundle\PluginManager::class);
$pluginManager->shouldReceive('getPlugin')->andReturn($mockPlugin);
$this->app->instance(\Codeages\PluginBundle\PluginManager::class, $pluginManager);
How can I help you explore Laravel packages today?