All Projects → sethsandaru → laravel-hmvc-sample

sethsandaru / laravel-hmvc-sample

Licence: other
Sample project, building a HMVC structure for Laravel 5,6,7,8

Programming Languages

PHP
23972 projects - #3 most used programming language
Blade
752 projects

Projects that are alternatives of or similar to laravel-hmvc-sample

Unitymathreference
Math reference for games and more. All visualized in Unity3D.
Stars: ✭ 166 (+492.86%)
Mutual labels:  sample
Daggerandroidinjector
Dagger Sample Project on how to use the new dagger-android module for Dagger v2.11
Stars: ✭ 195 (+596.43%)
Mutual labels:  sample
Peachpie Wordpress
WordPress running on .NET Core.
Stars: ✭ 237 (+746.43%)
Mutual labels:  sample
Reactnativeuniversal
A demonstration of sharing javascript react-native code between mobile, desktop and web environments
Stars: ✭ 178 (+535.71%)
Mutual labels:  sample
Openui5 Sample App
OpenUI5 Sample App
Stars: ✭ 193 (+589.29%)
Mutual labels:  sample
Machine Learning Diff Private Federated Learning
Simulate a federated setting and run differentially private federated learning.
Stars: ✭ 207 (+639.29%)
Mutual labels:  sample
Play Java Starter Example
Play starter project in Java (ideal for new users!)
Stars: ✭ 164 (+485.71%)
Mutual labels:  sample
Spring Framework Petclinic
A Spring Framework application based on JSP, Spring MVC, Spring Data JPA, Hibernate and JDBC
Stars: ✭ 251 (+796.43%)
Mutual labels:  sample
Play Scala Websocket Example
Example Play Scala application showing WebSocket use with Akka actors
Stars: ✭ 194 (+592.86%)
Mutual labels:  sample
Arkit2.0 Prototype
After Apple’s introduction of ARKit 2, we have been consistently working behind to create shared-AR experiences. Our goal is to improve the utility of mobile using AR experiences.
Stars: ✭ 236 (+742.86%)
Mutual labels:  sample
Fluttergames
Flutter app for purchasing and renting games.
Stars: ✭ 182 (+550%)
Mutual labels:  sample
Cognitive Face Ios
iOS SDK for the Microsoft Face API, part of Cognitive Services
Stars: ✭ 191 (+582.14%)
Mutual labels:  sample
Jethub
Sample App with Jetpack components(LiveData, Navigation, ViewModel) + MVVM + coroutine + single activity
Stars: ✭ 224 (+700%)
Mutual labels:  sample
Cognitive Face Windows
Windows SDK for the Microsoft Face API, part of Cognitive Services
Stars: ✭ 175 (+525%)
Mutual labels:  sample
Play Scala Starter Example
Play Scala Starter Template (ideal for new users!)
Stars: ✭ 238 (+750%)
Mutual labels:  sample
Kotlin Full Stack Application Demo
Full-stack demo application written with Kotlin MPP
Stars: ✭ 165 (+489.29%)
Mutual labels:  sample
Cloud Cap Samples
This project contains sample applications for SAP Cloud Application Programming Model.
Stars: ✭ 202 (+621.43%)
Mutual labels:  sample
laravel-vue-i18n
Allows to connect your `Laravel` Framework translation files with `Vue`.
Stars: ✭ 430 (+1435.71%)
Mutual labels:  laravel-framework
Golang Samples
Sample apps and code written for Google Cloud in the Go programming language.
Stars: ✭ 3,088 (+10928.57%)
Mutual labels:  sample
Cognitive Face Python
Python SDK for the Microsoft Face API, part of Cognitive Services
Stars: ✭ 226 (+707.14%)
Mutual labels:  sample

Laravel HMVC Structure - Sample Project

A sample project, building and using HMVC structure for Laravel 5.7+, 6, 7, 8.

What is HMVC?

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.
  • Usability: By nature of the design it is easy to reuse nearly every piece of code.
  • Extensibility: Makes the application more extensible without sacrificing ease of maintenance.

Other advantages

  • Able to achieve Microservice with ease. Splitting up the Modules into Services would be blazing fast.
  • In the Project itself it's like a Mono-Repo strategy.

Laravel HMVC Structure - this project

  • Top - Base MVC - Laravel App
    • Module 1 MVC - Small Laravel App
    • Module 2 MVC - Small Laravel App
    • ...
    • Module n MVC - Small Laravel App

Module Structure

  • ModuleName
    • Configs: Your config files here.
    • Http:
      • Controllers: Your controllers here.
      • Requests
    • 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: all the routes of the module
      • routes.php: routes of this module.
    • Services: your service handlers here
    • Providers: Service Provider
    • Policies: policies of the module

So you can see, a Module is just a small Laravel Application. You don't have to create a full structure to make it work.

The most important part is: ServiceProvider. Without that we can't boot up the Module.

How to create a new module?

  1. Create your module folder inside app/Modules
  2. Inside your module folder, create folder that you need like the structure above (ServiceProvider, Views,...)
  3. Create a ServiceProvider and register it in configs/app.php
  4. Test your module

How to access View/Language/Config?

Module folder name is the alias name to let us load views, language text,...
Example: I have Home module. Alias: home

Load view

We need to insert module alias in the beginning like this:

return view('home::home.view', $arrData);

Get language (translation) text

trans('home::home.hello'); // Hello
__('home::home.world'); // World

Get Config Value

Just like normal config, you can get your config via your alias like this:

config('home.text'); // get 'text' in home alias

Migrations

How it works?

When you run php artisan migrate, it will run like this:

- Base/Core (database/migrations) first
- Thought each module
    - Module 1
    - Module 2
    - ...
    - Module n

Create migration

Just create migration file (Laravel format) in <ModulePath>/Migrations.

Note:

  • Filename must be: yyyy_MM_dd_hhmmss_class_name_here.php (follow Laravel format)

Console Command registration

  • Create your command in app/Modules/<insert_module_name/Console/Commands
  • Open your module's ServiceProvider, register it in boot method like this:
$this->commands([
    MyCommand::class,
]);

Note: Older Laravel versions might not have this opportunity. The current project is using Laravel 5.7

Final

If you got any problems or any questions, feel free to ask me.

Copyright © 2018-2021 by Seth Phat.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].