Custom Own HMVC Basic Structure with Laravel Inside this blog, you will learn and be able to create your own custom basic HMVC structure that will help you to manage feature-wise separate code base and easily can be integrated inside another project in case the same module or feature exists on another project Let’s start […]
In any case, you changes in your file and that won't affect, you need to fire the below artisan command :
php artisan config:cache
<?php
# config/module.php
return [
'modules' => [
'Module_name_first',
'Module_Name_second',
]
];
Now, create a new directory named Modules inside the root level of your project, and this directory will store all the modules that are used inside the project.
Then we have to define our own service provider class to load and boot our all modules' routes, views, controllers, and other things from each module.
Create a service provider, named ModuleServiceProvider.php inside our modules directory:
To create a service run below artisan command below:
php artisan make:provider ModuleServiceProvider
And now move the ModuleServiceProvider.php to our Modules directory and change the namespace to namespace Modules; and update boot() from the below:
public function boot() {
// For each of the registered modules, include their routes and Views
$modules = config("module.modules");
while (list(,$module) = each($modules)) {
// Load the routes for each of the modules
if(file_exists(__DIR__.'/'.$module.'/routes.php')){
include __DIR__.'/'.$module.'/routes.php';
}
// Load the views
if(is_dir(__DIR__.'/'.$module.'/Views')) {
$this->loadViewsFrom(__DIR__.'/'.$module.'/Views', $module);
}//End If
}//END LOOP
}//End Function