Installation:
composer require alizharb/laravel-modular
php artisan modular:install
This sets up autoloading, Vite integration, and default paths.
Create First Module:
php artisan make:module Blog
This generates a fully structured module with:
module.json (configuration)composer.json (isolated dependencies)package.json (frontend dependencies)app/, resources/, etc.)Generate Resources:
php artisan make:model Post --module=Blog -mcf
php artisan make:controller API/PostController --module=Blog --api
Use the --module flag with any make: command to scaffold resources inside a module:
php artisan make:controller Admin/PostController --module=Blog --resource
This creates modules/Blog/app/Http/Controllers/Admin/PostController.php.
Modular Artisan Commands:
Override any Laravel make: command by adding --module=ModuleName:
php artisan make:policy PostPolicy --module=Blog
Dependency Management:
module.json:
{
"dependencies": ["Auth", "Database"]
}
composer.json:
php artisan modular:sync
Asset Pipeline:
modular_vite() in Blade:
@vite(['resources/js/app.js', modular_vite('Blog')])
php artisan modular:link
Database Operations:
php artisan modular:migrate Blog --fresh
php artisan modular:seed Blog
modules/ModuleName/app/Providers/ModuleNameServiceProvider.php.module.json:
"middleware": {
"web": ["Modules\\Blog\\Http\\Middleware\\VerifyBlogUser"]
}
event(new \Modules\Blog\Events\PostPublished());
php artisan modular:test Blog
vite.modular.js:
export const modularLoader = {
inputs: () => [
'modules/**/resources/js/*.js',
'modules/**/resources/css/*.css'
],
refreshPaths: () => [
'modules/**/resources/js/*.js',
'modules/**/resources/css/*.css'
]
};
vite.config.js:
import { modularLoader } from './vite.modular.js';
Circular Dependencies:
php artisan modular:check
module.json dependencies.Autoloading Issues:
"Modules\\": "modules/" exists in composer.json.composer dump-autoload
php artisan modular:cache
Missing Module Registration:
ModuleServiceProvider is registered in config/app.php under providers.php artisan modular:debug ModuleName
Blade Directives Not Working:
@moduleEnabled directives are used in Blade files within the resources/views directory of the module or root.Module Discovery:
php artisan modular:list --tree
Configuration: Publish config:
php artisan vendor:publish --tag="modular-config"
Customize paths, stubs, or composer defaults.
Performance:
php artisan modular:cache
php artisan modular:sync
Custom Stubs:
Override default stubs by placing them in modules/ModuleName/stubs/.
Dynamic Module Activation: Enable/disable modules at runtime:
php artisan module:enable Blog
php artisan module:disable Store
Hooks Integration: Use Laravel Hooks for extensibility:
Hook::add('blog.post.published', function () {
// Run after post is published
});
Filament/Livewire: Integrate with Modular Filament or Modular Livewire for admin panel or frontend component support.
config('Blog::settings.key');
config('blog::settings.key');
config/modular.php:
'paths' => [
'modules' => base_path('packages'),
],
Isolated Development:
Use php artisan modular:npm Blog install to manage frontend dependencies per module.
Zero-Downtime Deployments:
Leverage modular:cache to avoid autoload regeneration during deployments.
Standalone Modules: Export modules as Composer packages:
php artisan modular:export Blog --path=packages/blog
How can I help you explore Laravel packages today?