Laravel Module Management

Oct 02, 2017 Laravel Framework PHP
Module Manager Laravel | Learn2torials

What is laravel module management?

Laravel module management is a laravel plugin that you can use to create modular application using laravel framework. This plugin helps a developer to create module based web application. For example, if you are a developer and working on a bigger application then you might want to chunk your project into smaller modules. Say you have a blog website and you want to encapsulate logic in modules.


  • post module
  • category module
  • user module

Using this package you will be able to create such modules and you can turn them on/off using configuration file. You can even create configs related to your modules. You will understand as we move on to this tutorial.

How to install Laravel module management package?

Let's take one example: if you are working on a web app using laravel framework and your clients need a functionality to turn some feature of your web app on/off then this package will help you achieve that.

Using this package you will be able to create small modules within your laravel application and using config file you can turn them on/off. To install my package go to your laravel project root directory and run following commands in your terminal:

# install composer package
composer require phpcodebooster/laravel

# import config file from vendor to config file
# if you do not see modules.php file in config folder
# create a new file in config folder called modules.php
php artisan vendor:publish

How to create laravel modules?

Let's understand how to create a small post module in our laravel application. let's create following directory structure for our sample "post" module:

    └── Modules/
        └── Post/
            ├── Controllers/
            ├── Models/
            ├── Views/
            ├── Migrations/
            ├── Translations/
            ├── routes.php
            └── config.php    

Create a sample route

Let's create another file called HomeController in App/Modules/Admin/Controllers and add following contents to it:


namespace App\Modules\Post\Controllers;
use App\Http\Controllers\Controller;

class HomeController extends Controller
    public function index()
        return view('post::index');

Create a view file

Finally, create a view file called index.php in App\Modules\Post\Views with following contents:

<h1>Sample Post Module</h1>

Now, that we have created our module files and structure. We need to turn this functionality on using config/modules.php file. Make sure you have this structure in order to work my package. Now, we have to turn post module on so that we can use it. Open config/modules.php file and add following line:

return [
   'enabled' => [
       'post' => 'Post Module'  // make sure key is lowercase

You can create migration file for your post table in App\Modules\Post\Migrations and Post model in App\Modules\Post\Models if necessary. The idea is to keep post related stuff in Post module so that we can use this module without affecting other code.

For other developers it is easy to go and check module related functionality rather then touching code everywhere. Once you followed the steps above it's time to see our post module in action.

Open your browser and go to http://localhost/post and see our post module index file contents. If you want to download this module click here Post Module

Rate This Article

How to manage modular application using laravel 5 framrwork


About Author