Laravel | laravel-modules |
---|---|
5.4 | ^1.0 |
5.5 | ^2.0 |
nwidart/laravel-modules
is a Laravel package which created to manage your large Laravel app using modules. Module is like a Laravel package, it has some views, controllers or models. This package is supported and tested in Laravel 5.
This package is a re-published, re-organised and maintained version of pingpong/modules, which isn't maintained anymore. This package is used in AsgardCMS.
With one big added bonus that the original package didn't have: tests.
Find out why you should use this package in the article: Writing modular applications with laravel-modules.
To install through Composer, by run the following command:
composer require nwidart/laravel-modules
The package will automatically register a service provider and alias.
Optionally, publish the package's configuration file by running:
php artisan vendor:publish --provider="Nwidart\Modules\LaravelModulesServiceProvider"
Lumen doesn't come with a vendor publisher. In order to use laravel-modules with lumen you have to set it up manually.
create a config folder inside the root directory and copy vendor/nwidart/laravel-modules/config/config.php to that folder named modules.php
mkdir config
cp vendor/nwidart/laravel-modules/config/config.php config/modules.php
then load the config and the serviceprovider in app/bootstrap.php
$app->configure('modules');
$app->register(Nwidart\Modules\LumenModulesServiceProvider::class)
Laravel-modules uses path.public which isn't defined by default in Lumen. register path.public before loading the serviceprovider.
$app->bind('path.public', function() {
return __DIR__ . 'public/';
});
By default the module classes are not loaded automatically. You can autoload your modules using psr-4
. For example:
{
"autoload": {
"psr-4": {
"App\\": "app/",
"Modules\\": "Modules/"
}
}
}
Tip: don't forget to run composer dump-autoload
afterwards.
You'll find installation instructions and full documentation on https://nwidart.com/laravel-modules/.
Nicolas Widart is a freelance web developer specialising on the Laravel framework. View all my packages on my website.
The MIT License (MIT). Please see License File for more information.