Module Lifecycle
Enable, disable, install, update, and remove modules
Module States
Modules can be in two states:
| State | Description |
|---|---|
| Enabled | Module is active, its providers are loaded |
| Disabled | Module exists but is not loaded |
Enabling Modules
Via CLI
php artisan modular:enable Blog
Programmatically
use Esegments\ModularArchitecture\Facades\Modular;
Modular::enable('Blog');
What Happens on Enable
- Dependencies are validated
BeforeModuleEnableextension point fires- Module state is updated
ModuleEnabledextension point fires- Cache is cleared
Disabling Modules
Via CLI
php artisan modular:disable Blog
Programmatically
Modular::disable('Blog');
What Happens on Disable
- Dependents are checked (modules that depend on this one)
BeforeModuleDisableextension point fires- Module state is updated
ModuleDisabledextension point fires- Cache is cleared
Protected Modules
Some modules cannot be disabled:
// config/modular.php
'protected' => [
'Core',
'Admin',
],
php artisan modular:disable Core
# Error: Module [Core] is protected and cannot be disabled.
Installing Modules
From GitHub
php artisan modular:install vendor/repo
php artisan modular:install E-Segments/blog-module
# With specific version
php artisan modular:install vendor/repo --ver=1.2.0
# With specific branch
php artisan modular:install vendor/repo --branch=develop
What Happens on Install
BeforeModuleInstallextension point fires- Module is downloaded from GitHub
- Archive is extracted to Modules directory
- Dependencies are validated
ModuleInstalledextension point fires- Module is auto-enabled (optional)
GitHub Authentication
For private repos, set your token:
GITHUB_TOKEN=your_personal_access_token
Updating Modules
Via CLI
php artisan modular:update Blog
Check for Updates
php artisan modular:outdated
What Happens on Update
- Current module is backed up
- New version is downloaded
- Files are replaced
- If update fails, backup is restored
Removing Modules
Via CLI
php artisan modular:remove Blog
With Force
php artisan modular:remove Blog --force
What Happens on Remove
- Dependents are checked
BeforeModuleUninstallextension point fires- Module files are deleted
ModuleUninstalledextension point fires- Cache is cleared
Running Migrations
All Modules
php artisan modular:migrate
Specific Module
php artisan modular:migrate Blog
With Options
php artisan modular:migrate Blog --seed
php artisan modular:migrate --rollback
php artisan modular:migrate --reset
php artisan modular:migrate --refresh
What Happens on Migrate
BeforeModuleMigrateextension point fires- Migrations run
ModuleMigratedextension point fires
Running Seeders
php artisan modular:seed Blog
What Happens on Seed
BeforeModuleSeedextension point fires- Seeders run
ModuleSeededextension point fires
Lifecycle Diagram
┌─────────────────────────────────────────────────────────────┐
│ Module Lifecycle │
├─────────────────────────────────────────────────────────────┤
│ │
│ ┌──────────┐ enable ┌──────────┐ │
│ │ Disabled │ ──────────────▶ │ Enabled │ │
│ └──────────┘ └──────────┘ │
│ │ │ │
│ │ remove │ disable │
│ ▼ ▼ │
│ ┌──────────┐ ┌──────────┐ │
│ │ Removed │ │ Disabled │ │
│ └──────────┘ └──────────┘ │
│ │
│ Install ──▶ Disabled ──▶ Enable ──▶ Migrate ──▶ Seed │
│ │
└─────────────────────────────────────────────────────────────┘
Checking Module Status
php artisan modular:status Blog
Output:
Module: Blog
├── Version: 1.2.0
├── Status: Enabled
├── Protected: No
├── Path: /var/www/Modules/Blog
├── Namespace: Modules\Blog
├── Dependencies:
│ ├── Core: ^1.0 (satisfied)
│ └── Media: ^2.0 (satisfied)
└── Dependents:
└── Comments (requires Blog ^1.0)