Download the PHP package zonneplan/laravel-module-loader without Composer
On this page you can find all versions of the php package zonneplan/laravel-module-loader. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package laravel-module-loader
Module loader inside your Laravel app
| Laravel | laravel-module-loader |
|---|---|
| 5.8 | ^1.0 |
| 6.0 | ^1.0 |
| 7.0 | ^1.0 |
| 8.0 | ^2.0 |
| 9.0 | ^3.0 |
| 10.0 | ^4.0 |
| 11.0 | ^5.0 |
| 12.0 | ^6.0 |
| 13.0 | ^7.0 |
The zonneplan/laravel-module-loader package provides an easy to use module loader
which can be used to modulize your project.
How to use
First install the package, see the installation section.
Creating a new module:
- Create a folder, for example:
Modulesin the app directory. - After that create another one, for example:
User. - In the root of that folder insert a
UserServiceProviderwhich extends our abstractModuleclass. -
Implement the function
getModuleNamespace()like: - Register the
UserServiceProviderin theconfig/app.phpfile.
Structure within the module:
The expected structure is seen below. Most of it is optional.
Access a view from the module:
To access a view from a module it will look like 'my-module::path.to.view'
For example: `
Registering Policies:
To register policies overwrite the $policies variable in the ServiceProvider of your module
For example:
Registering Middleware:
To register middleware overwrite the $middleware variable in the ServiceProvider of your module
For example:
Registering Events & Listeners:
To register events & listeners overwrite the $listen variable in the ServiceProvider of your module
For example:
Registering Event Subscribers:
To register event subscribers overwrite the $subscribe variable in the ServiceProvider of your module
For example:
Registering routes:
All modules will by default try to load all route files in the Routes folder.
Any of the following files will be auto loaded:
routes.php api.php web.php mcp.php
These files are loaded without a route group, so they don't get the web or api middleware group, a prefix or a
domain from the application. Declare the middleware (authentication, throttling, etc.), prefix and domain in the route
file itself:
Don't load these files again with Route::module($name, 'api') or Route::modules('api') (or web/mcp) inside a
group with a prefix or domain: the auto-loaded copy would stay reachable without the group's middleware. The macros
throw a LogicException in that case. A middleware-only group is allowed, because its routes replace the auto-loaded
ones.
Profiling module loading:
Module loading profiling is disabled by default. Publish the config file to enable it:
The following environment variables are available:
Supported drivers:
log: writes structured timing records to the configured Laravel log channel.callback: callsmodule-loader.profiling.reporter, which may be a callable or a class with ahandle(array $measurement)method.event: dispatches aZonneplan\ModuleLoader\Events\ModuleProfiledevent with the measurement.
The base register() and boot() methods are profiled when enabled. If include_steps is enabled, the built-in boot steps like config, translation, view, policy, route, and middleware loading are profiled separately. The sample_rate value is evaluated once per request or process, so sampled runs keep a complete module loading profile.
OpenTelemetry is intentionally not a dependency of this package. Applications that want OpenTelemetry spans can install open-telemetry/api and convert profiling measurements to spans from a callback reporter or a ModuleProfiled listener.
Requirements
This package requires at least Laravel 6 or higher, PHP 7.2 or higher
Installation
composer require zonneplan/laravel-module-loader
The package will automatically register itself.
Register the namespace: "Modules\\": "app/Modules" in composer.json like:
Authors
- Aron Rotteveel
- Dennis Stolmeijer
- Wout Hoeve
- Johnny Borg
- Rick Gout
- Thijs Nijholt
All versions of laravel-module-loader with dependencies
illuminate/console Version ^12.0||^13.0
illuminate/database Version ^12.0||^13.0
illuminate/support Version ^12.0||^13.0
illuminate/routing Version ^12.0||^13.0