Requirements
Before installing Laravel Modular, ensure your environment meets these requirements:- PHP 8.3 or higher
- Laravel 11, 12, or dev-master/dev-main
- Composer 2.1 or higher
Install the Package
Install Laravel Modular via Composer:The package uses Laravel’s auto-discovery feature, so you don’t need to manually register any service providers or facades.
Publish Configuration (Recommended)
While not strictly required, it’s highly recommended that you publish and customize the configuration file. This allows you to set a custom namespace for your modules, making it easier to extract them to standalone packages later.Why Customize the Namespace?
By default, modules are created in theModules\ namespace. While this works fine, using your organization name (like MyCompany\ or Acme\) provides several benefits:
- Easier to extract modules to separate packages
- Better code organization across projects
- Clearer ownership and provenance
Publish the Config
Run the following command to publish the configuration file:config/app-modules.php in your application.
Configure Your Namespace
Openconfig/app-modules.php and customize the modules_namespace setting:
config/app-modules.php
Configuration Options
modules_namespace
modules_namespace
The PHP namespace for your modules. For example, if set to
Acme, a module named “blog” would use the namespace Acme\Blog.Default: ModulesRecommended: Your organization or project name in StudlyCase (e.g., Acme, MyCompany)modules_vendor
modules_vendor
The Composer vendor prefix for your modules. This is used in the module’s
composer.json file.Default: null (auto-generates from modules_namespace)Example: acme for namespace Acmemodules_directory
modules_directory
The directory where modules are stored, relative to your Laravel project root.Default:
app-modulesNote: Keeping the default is recommended as it maintains alphabetical proximity to the app/ directory.tests_base
tests_base
The fully qualified class name of your base test case class.Default:
Tests\TestCaseshould_discover_events
should_discover_events
Override automatic event discovery. Set to
true or false to explicitly enable or disable.Default: null (uses Laravel’s default behavior)stubs
stubs
Custom stub files for scaffolding new modules. See the customization guide for details.Default:
null (uses built-in stubs)Sync Project Configuration (Optional)
Run the sync command to update your project configuration files:phpunit.xml- Adds a test suite for your modules- PhpStorm Laravel plugin config - Registers module view paths
composer.json to run automatically:
composer.json
Verify Installation
You can verify the installation by running:What’s Next?
Create Your First Module
Follow the quick start guide to create and explore your first module