Javatpoint Logo
Javatpoint Logo

Laravel 5.7 Modular Structure Application

In this section, we are going to create a modular structure application. We will use Laravel 5.7 to do this. Here, we will use the package of nWidart/laravel-modules to make a design pattern of modular structure. This package is used to set up the command to quickly and easily create a module. Using this, a separate folder will be created for each module.

We had seen the structure of Laravel, such as console, views, helper, controller, model, providers, migration, etc, while we started working on Laravel. But at that time, we realized that we could make it more understandable and useful by making it modular. It will be more fantastic if the module is created for every curd specified Laravel such as item, country, product, city, state, etc, because if we do this, we can easily reuse it in our application. The approach of modular structure is very nice. That's why it is more useful.

In our Laravel application, we will use the package of laravel-modules composer to create a modular structure. In the Laravel application, we can create modular structure by using the many other packages, but the laravel-modules package is used to create "Module" directory and subdirectory, which is very easy and understandable. The folder has many listed things, which is described as follows:

  • Entity
  • Config
  • Tests
  • Database
  • Routes
  • Provides
  • Http
  • Console

This section will be useful when we need to make our application modular. For this, we will install the service provider and package of laravel- modules composer. In order to install the package of laravel-modules, the following will be useful like this:


In the process of setup, we will Install a package of laravel-modules. The following command will be used to do this:

After that, we will Publish the configuration file. The following command will be used to do this:

Then we will use the autoload file with Adding:composer.json.

After that, we will execute the following command like this:

Now we can use the package of laravel-module to create a module. Now we will use the following syntax to create the new package.

Create Module Syntax:

Create Module Example:

When we successfully run the above code, we will open our app folder and see the newly created Modules directory and Migration. The structure of it is described as follows:

We can see views, models, routes, controller, helper, database, and repository in the above application. If we want more modules, we can easily create them. In order to run the above code, we will run the following command:

Now we can use our browser to open the below URL:

After open this, we can see the following output:

Laravel 5.7 Modular Structure Application

Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA