This Laravel project follows the Hierarchical Model-View-Controller (HMVC) architecture, providing a modular structure for easier maintenance and scalability.
laravel_hmvc_project/ |-- app/ |-- bootstrap/ |-- config/ |-- database/ |-- modules/ | |-- Module1/ | | |-- Controllers/ | | |-- Models/ | | |-- Views/ | | |-- ... | | | |-- Module2/ | | |-- Controllers/ | | |-- Models/ | | |-- Views/ | | |-- ... | | | |-- ... | |-- public/ |-- resources/ |-- routes/ |-- ...
git clone https://github.com/your-username/your-repository.git composer install php artisan key:generate php artisan migrate php artisan serve
php artisan make:module ModuleName php artisan module:make posts php artisan module:make Blog --api (for api module)
php artisan module:make-migration create_posts_table Blog php artisan module:make-seed seed_fake_blog_posts Blog php artisan module:make-controller PostsController Blog
By default when you create a new module, the command will add some resources like a controller, seed class, service provider, etc. automatically. If you don’t want these, you can add --plain flag, to generate a plain module.
php artisan module:make Blog --plain
or
php artisan module:make Blog -p
Generate an api module.
php artisan module:make Blog --api
php artisan module:make Blog --disabled
or
php artisan module:make Blog -d
You can use the following commands with the --help suffix to find its arguments and options.
Note all the following commands use “Blog” as example module name, and example class/file names
module:make
php artisan module:make Blog
module:make
php artisan module:make Blog User Auth
module:use
Use a given module. This allows you to not specify the module name on other commands requiring the module name as an argument.
php artisan module:use Blog
module:unuse
php artisan module:unuse
module:list
php artisan module:list
module:migrate
php artisan module:migrate Blog
module:migrate-rollback
php artisan module:migrate-rollback Blog
module:migrate-refresh
Refresh the migration for the given module, or without a specified module refresh all modules migrations.
php artisan module:migrate-refresh Blog
module:migrate-reset Blog
Reset the migration for the given module, or without a specified module reset all modules migrations.
php artisan module:migrate-reset Blog
module:seed
php artisan module:seed Blog
module:publish-migration
Publish the migration files for the given module, or without an argument publish all modules migrations.
php artisan module:publish-migration Blog
module:publish-config
Publish the given module configuration files, or without an argument publish all modules configuration files.
php artisan module:publish-config Blog
module:publish-translation
Publish the translation files for the given module, or without a specified module publish all modules migrations.
php artisan module:publish-translation Blog
module:enable
php artisan module:enable Blog
module:disable
php artisan module:disable Blog
module:update
php artisan module:update Blog
module:make-command
php artisan module:make-command CreatePostCommand Blog
module:make-migration
php artisan module:make-migration create_posts_table Blog
module:make-seed
php artisan module:make-seed seed_fake_blog_posts Blog
module:make-controller
php artisan module:make-controller PostsController Blog
module:make-model
php artisan module:make-model Post Blog
--migration, -m: create the migration file for the given model
module:make-provider
php artisan module:make-provider BlogServiceProvider Blog
module:make-middleware
php artisan module:make-middleware CanReadPostsMiddleware Blog
module:make-mail
php artisan module:make-mail SendWeeklyPostsEmail Blog
module:make-notification
php artisan module:make-notification NotifyAdminOfNewComment Blog
module:make-listener
Generate the given listener for the specified module. Optionally you can specify which event class it should listen to. It also accepts a --queued flag allowed queued event listeners.
php artisan module:make-listener NotifyUsersOfANewPost Blog
php artisan module:make-listener NotifyUsersOfANewPost Blog --event=PostWasCreated
php artisan module:make-listener NotifyUsersOfANewPost Blog --event=PostWasCreated --queued
module:make-request
php artisan module:make-request CreatePostRequest Blog
module:make-event
php artisan module:make-event BlogPostWasUpdated Blog
module:make-job
php artisan module:make-job JobName Blog
php artisan module:make-job JobName Blog --sync # A synchronous job class
module:route-provider
php artisan module:route-provider Blog
module:make-factory
php artisan module:make-factory ModelName Blog
module:make-policy
The Policies is not generated by default when creating a new module. Change the value of paths.generator.policies in modules.php to your desired location.
php artisan module:make-policy PolicyName Blog
module:make-rule
The Rules folder is not generated by default when creating a new module. Change the value of paths.generator.rules in modules.php to your desired location.
php artisan module:make-rule ValidationRule Blog
module:make-resource
Generate the given resource class for the specified module. It can have an optional --collection argument to generate a resource collection.
The Transformers folder is not generated by default when creating a new module. Change the value of paths.generator.resource in modules.php to your desired location.
php artisan module:make-resource PostResource Blog
php artisan module:make-resource PostResource Blog --collection
module:make-test
php artisan module:make-test EloquentPostRepositoryTest Blog
Syntax of create module command:
php artisan make:module module_name
Then run the following command to create module let’s do an example for Posts module.
php artisan make:module posts
After running above commands it will generate our Posts module under Modules folder. See below Laravel module structures:
app/
bootstrap/
vendor/
Modules/
├── Posts/
├── Assets/
├── Config/
├── Console/
├── Database/
├── Migrations/
├── Seeders/
├── Entities/
├── Http/
├── Controllers/
├── Middleware/
├── Requests/
├── Providers/
├── PostsServiceProvider.php
├── RouteServiceProvider.php
├── Resources/
├── assets/
├── js/
├── app.js
├── sass/
├── app.scss
├── lang/
├── views/
├── Routes/
├── api.php
├── web.php
├── Repositories/
├── Tests/
├── composer.json
├── module.json
├── package.json
├── webpack.mix.js
php artisan serve
```composer install
php artisan key:generate
php artisan storage:link
php artisan migrate
php artisan db:seed
php artisan cache:clear
php artisan config:clear
php artisan view:clear
php artisan config:cache
php artisan view:cache
php artisan route:cache
composer dump-autoload```