How to create 'Modules' on a Laravel 5.3 installation
How to create 'Modules' on a Laravel 5.3 installation
Step1: Create Folder “Modules” inside “app/”
Step2: In Modules folder create your Module (Module1( suppose admin Module))
Inside admin module : create the following folder
1. Controllers (here will your controller files)
2. Views (here will your View files)
3. Models (here will your Model files)
4. routes.php (here will your route code in this file)
Similarly, You can create another module
Module2( suppose API )
-Controllers
-Views
-Models
-routes.php
Similarly, you can create multiple modules
Step3 : Create ModuleServiceProvider.php inside “app/Providers/” Folder
Step4 : Paste following code inside ModuleServiceProvider.php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
class ModuleServiceProvider extends ServiceProvider
{
/**
* Will make sure that the required modules have been fully loaded
* @return void
*/
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(base_path('app/Modules/'.$module.'/routes.php'))) {
include base_path('app/Modules/'.$module.'/routes.php');
}
// Load the views
if(is_dir(base_path('app/Modules/'.$module.'/Views'))) {
$this->loadViewsFrom(base_path('app/Modules/'.$module.'/Views'), $module);
}
}
}
public function register() {}
}
Step5 : Add following line inside ‘config/app.php’ file
App\Providers\ModuleServiceProvider::class,
Step6 : Create module.php file inside ‘config’ folder
Step7 : Add following code inside module.php (path => “config/module.php”)
return [
'modules' => [
'User',
'Theme',
],];
Note : You can add your module name whichever you have created. Here there are modules.
Step8 : Run this command
composer dump-autoload - for updating
We will add more information here so stay tuned...
Published: 9th November 2016 by