Module Management In Laravel
Latest commit fc0f562 Jan 19, 2017 @nWidart committed on GitHub Merge pull request #127 from ecodrutz/patch-1
Fixed typo in README.MD


Latest Version on Packagist Software License Build Status Scrutinizer Coverage SensioLabsInsight Quality Score Total Downloads

nwidart/laravel-modules is a laravel package which created to manage your large laravel app using modules. Module is like a laravel package, it has some views, controllers or models. This package is supported and tested in Laravel 5.

This package is a re-published, re-organised and maintained version of pingpong/modules, which isn't maintained anymore. This package is used in AsgardCMS.

With one big added bonus that the original package didn't have: tests.

Find out why you should use this package in the article: Writing modular applications with laravel-modules.

Upgrade Guide



To install through composer, simply run the following command:

composer require nwidart/laravel-modules

Add Service Provider

Next add the following service provider in config/app.php.

'providers' => [

Next, add the following aliases to aliases array in the same file.

'aliases' => [
  'Module' => Nwidart\Modules\Facades\Module::class,

Next publish the package's configuration file by running :

php artisan vendor:publish --provider="Nwidart\Modules\LaravelModulesServiceProvider"


By default controllers, entities or repositories are not loaded automatically. You can autoload your modules using psr-4. For example :

  "autoload": {
    "psr-4": {
      "App\\": "app/",
      "Modules\\": "Modules/"


  • modules - Used for save the generated modules.
  • assets - Used for save the modules's assets from each modules.
  • migration - Used for save the modules's migrations if you publish the modules's migrations.
  • generator - Used for generate modules folders.
  • scan - Used for allow to scan other folders.
  • enabled - If true, the package will scan other paths. By default the value is false
  • paths - The list of path which can scanned automatically by the package.
  • composer
  • vendor - Composer vendor name.
  • - Composer author name.
  • - Composer author email.
  • cache
  • enabled - If true, the scanned modules (all modules) will cached automatically. By default the value is false
  • key - The name of cache.
  • lifetime - Lifetime of cache.

Creating A Module

To create a new module you can simply run :

php artisan module:make <module-name>
  • <module-name> - Required. The name of module will be created.

Create a new module

php artisan module:make Blog

Create multiple modules

php artisan module:make Blog User Auth

By default if you create a new module, that will add some resources like controller, seed class or provider automatically. If you don't want these, you can add --plain flag, to generate a plain module.

php artisan module:make Blog --plain
php artisan module:make Blog -p

Naming Convension

Because we are autoloading the modules using psr-4, we strongly recommend using StudlyCase convension.

Folder Structure

  ├── Blog/
      ├── Assets/
      ├── Config/
      ├── Console/
      ├── Database/
          ├── Migrations/
          ├── Seeders/
      ├── Entities/
      ├── Http/
          ├── Controllers/
          ├── Middleware/
          ├── Requests/
          ├── routes.php
      ├── Providers/
          ├── BlogServiceProvider.php
      ├── Resources/
          ├── lang/
          ├── views/
      ├── Repositories/
      ├── Tests/
      ├── composer.json
      ├── module.json
      ├── start.php

Artisan Commands

Create new module.

php artisan module:make blog

Use the specified module.

php artisan module:use blog

Show all modules in command line.

php artisan module:list

Create new command for the specified module.

php artisan module:make-command CustomCommand blog

php artisan module:make-command CustomCommand --command=custom:command blog

php artisan module:make-command CustomCommand --namespace=Modules\Blog\Commands blog

Create new migration for the specified module.

php artisan module:make-migration create_users_table blog

php artisan module:make-migration create_users_table --fields="username:string, password:string" blog

php artisan module:make-migration add_email_to_users_table --fields="email:string:unique" blog

php artisan module:make-migration remove_email_from_users_table --fields="email:string:unique" blog

php artisan module:make-migration drop_users_table blog

Rollback, Reset and Refresh The Modules Migrations.

php artisan module:migrate-rollback

php artisan module:migrate-reset

php artisan module:migrate-refresh

Rollback, Reset and Refresh The Migrations for the specified module.

php artisan module:migrate-rollback blog

php artisan module:migrate-reset blog

php artisan module:migrate-refresh blog

Create new seed for the specified module.

php artisan module:make-seed users blog

Migrate from the specified module.

php artisan module:migrate blog

Migrate from all modules.

php artisan module:migrate

Seed from the specified module.

php artisan module:seed blog

Seed from all modules.

php artisan module:seed

Create new controller for the specified module.

php artisan module:make-controller SiteController blog

Publish assets from the specified module to public directory.

php artisan module:publish blog

Publish assets from all modules to public directory.

php artisan module:publish

Create new model for the specified module.

php artisan module:make-model User blog

php artisan module:make-model User blog --fillable="username,email,password"

Create new service provider for the specified module.

php artisan module:make-provider MyServiceProvider blog

Publish migration for the specified module or for all modules.

This helpful when you want to rollback the migrations. You can also run php artisan migrate instead of php artisan module:migrate command for migrate the migrations.

For the specified module.

php artisan module:publish-migration blog

For all modules.

php artisan module:publish-migration

Publish Module configuration files

php artisan module:publish-config <module-name>
  • (optional) module-name: The name of the module to publish configuration. Leaving blank will publish all modules.
  • (optional) --force: To force the publishing, overwriting already published files

Enable the specified module.

php artisan module:enable blog

Disable the specified module.

php artisan module:disable blog

Generate new middleware class.

php artisan module:make-middleware Auth

Generate new mailable class.

php artisan module:make-mail WelcomeEmail

Generate new notification class.

php artisan module:make-notification InvoicePaid

Update dependencies for the specified module.

php artisan module:update ModuleName

Update dependencies for all modules.

php artisan module:update

Show the list of modules.

php artisan module:list


Get all modules.


Get all cached modules.


Get ordered modules. The modules will be ordered by the priority key in module.json file.


Get scanned modules.


Find a specific module.

// OR

Find a module, if there is one, return the Module instance, otherwise throw Nwidart\Modules\Exeptions\ModuleNotFoundException.


Get scanned paths.


Get all modules as a collection instance.


Get modules by the status. 1 for active and 0 for inactive.


Check the specified module. If it exists, will return true, otherwise false.


Get all enabled modules.


Get all disabled modules.


Get count of all modules.


Get module path.


Register the modules.


Boot all available modules.


Get all enabled modules as collection instance.


Get module path from the specified module.


Get assets path from the specified module.


Get config value from this package.


Get used storage path.


Get used module for cli session.

// OR

Set used module for cli session.


Get modules's assets path.


Get asset url from specific module.


Install the specified module by given module name.


Update dependencies for the specified module.


Add a macro to the module repository.

Module::macro('hello', function() {
    echo "I'm a macro";

Call a macro from the module repository.


Get all required modules of a module

Module::getRequirements('module name');

Module Entity

Get an entity from a specific module.

$module = Module::find('blog');

Get module name.


Get module name in lowercase.


Get module name in studlycase.


Get module path.


Get extra path.


Disable the specified module.


Enable the specified module.


Delete the specified module.


Get an array of module requirements. Note: these should be aliases of the module.


Custom Namespaces

When you create a new module it also registers new custom namespace for Lang, View and Config. For example, if you create a new module named blog, it will also register new namespace/hint blog for that module. Then, you can use that namespace for calling Lang, View or Config. Following are some examples of its usage:

Calling Lang:


Calling View:



Calling Config:


Publishing Modules

Have you created a laravel modules? Yes, I've. Then, I want to publish my modules. Where do I publish it? That's the question. What's the answer ? The answer is Packagist.

Auto Scan Vendor Directory

By default the vendor directory is not scanned automatically, you need to update the configuration file to allow that. Set scan.enabled value to true. For example :

// file config/modules.php

return [
  'scan' => [
    'enabled' => true

You can verify the module has been installed using module:list command:

php artisan module:list

Publishing Modules

After creating a module and you are sure your module module will be used by other developers. You can push your module to github or bitbucket and after that you can submit your module to the packagist website.

You can follow this step to publish your module.

  1. Create A Module.
  2. Push the module to github.
  3. Submit your module to the packagist website. Submit to packagist is very easy, just give your github repository, click submit and you done.


About Nicolas Widart

Nicolas Widart is a freelance web developer specialising on the laravel framework. View all my packages on my website.


The MIT License (MIT). Please see License File for more information.