A sample project, building and using HMVC structure for Laravel 5.x.
You can find out here: HMVC - WIKI
Key advantages (M.O.R.E):
- Modularization: Reduction of dependencies between the disparate parts of the application.
- Organization: Having a folder for each of the relevant triads makes for a lighter work load.
- Reusability: By nature of the design it is easy to reuse nearly every piece of code.
- Extendibility: Makes the application more extensible without sacrificing ease of maintenance.
- Top - Base MVC
- Module 1 MVC
- Module 2 MVC
- ...
- Module n MVC
- Module
- Configs: Your config files here.
- Controllers: Your controllers here.
- Languages: your language files here (translation)
- en
- vi
- ...
- Libraries: your special library classes file here.
- Models: your models here.
- Views: your view file here.
- routes.php: routes of this module.
You don't need to have full structure to work properly. Create the one that you need to use.
- Create your module folder inside
app/Modules - Inside your module folder, create folder that you need like the structure above (Controllers, Views,...)
- Test your module.
Module folder name is the alias name to let us load views, language text,...
Example: I have Home module.
We need to insert module alias in the beginning like this:
return view('Home::home.view', $arrData);trans('Home::home.hello'); // HelloTo deal with your own config, we have 2 steps:
Just create a config file (Laravel format) in <ModulePath>/Configs.
- Open
HMVCServiceProvider.php - In
$configFilearray, add your config file and alias in here:
private $configFile = [
// alias => config file location/path
'homeconfig' => 'Home/Configs/homeconfig.php',
// more here
];Just like normal config, you can get your config via your alias like this:
config('homeconfig.text'); // get 'text' in homeconfigWhen you run php artisan migrate, it will run like this:
- Base/Core (database/migrations) first
- Thought each module
- Module 1
- Module 2
- ...
- Module nJust create migration file (Laravel format) in <ModulePath>/Migrations.
Note:
- Filename must be:
yyyy_MM_dd_hhmmss_class_name_here.php(follow Laravel format)
I'll create a laravel package (console) to create a module later :D
If you got any problems or any questions, feel free to ask me.
Copyright © 2018 by Phat Tran Minh - Seth Phat.