Download the PHP package prometa/laravel-modules without Composer
On this page you can find all versions of the php package prometa/laravel-modules. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download prometa/laravel-modules
More information about prometa/laravel-modules
Files in prometa/laravel-modules
Package laravel-modules
Short Description Helpers for bootstrapping modular Laravel apps (routes, commands, migrations, and service providers).
License MIT
Informations about the package laravel-modules
prometa/laravel-modules
Helpers for bootstrapping modular Laravel apps. It provides a single trait you can mix into your module ServiceProviders to:
- auto-load module routes (via
map()orroutes()), - auto-register module commands (scan the module folder),
- auto-register module migrations and translations,
Requirements
- PHP ^8.2
- Laravel >=12 (see
composer.json)
Installation
Usage
Use the trait in each module’s ServiceProvider:
When you have your own register() or boot()
BootstrapsModule defines register() and boot(). If your ServiceProvider also defines
one of those methods, you need to alias the trait methods so you can call both:
If you only override register() (or only boot()), you only need to alias that one.
Module folder schema
The trait assumes one module per folder under app/ (snake_case recommended), and uses the module name from the ServiceProvider’s namespace (last segment).
Minimal example:
Full example (optional parts):
What happens automatically
- Routes: if the ServiceProvider has a
map()method, it is called after boot.
Alternatively you can call$this->routes(fn () => ...)insideregister(). This is only needed if the Module has Routes to load. -
Commands: when running in console, the module directory is scanned.
Any non-abstract class that extendsIlluminate\Console\Commandis registered. -
Migrations:
app/<module>/migrationsis loaded when running in console. -
Translations:
app/<module>/langis loaded and namespaced as<module>. - Views:
app/<module>is registered as a view namespace<module>(so any subfolders are allowed, e.g.app/<module>/reports/index.blade.php→view('<module>::reports.index')).
Defining routes
You have two options:
1) map() method (most common)
2) routes() closure (useful if you want to keep all routing inside register())
If you do neither, the module simply has no routes.
Route attributes integration (optional)
If you use spatie/laravel-route-attributes, the trait automatically appends the module
root to route-attributes.directories with sane defaults:
prefix= module namepatterns=*Controller.php- no middleware
This keeps routes concise while allowing full control via attributes.
The integration is opt-in by presence: we only enable it if
Spatie\RouteAttributes\RouteAttributesServiceProvider exists.
Customize or disable
You can override the config per module by implementing this method in your ServiceProvider:
To disable the auto-registration for a module, override:
Notes
- The module name is inferred from the ServiceProvider’s namespace, e.g.
App\traffic\ServiceProvider→ module nametraffic. - The command scanner builds class names based on your app namespace (
App\) and file paths.