Laravel 5.7 Modular Structure Application Example

Laravel 5.7 Modular Structure Application Example

In this post we will give you information about Laravel 5.7 Modular Structure Application Example. Hear we will give you detail about Laravel 5.7 Modular Structure Application ExampleAnd how to use it also give you demo for it if it is necessary.

In this tutorial, i would like to show you how to create modular system for your laravel 5.7 application. i will give you suggestion to write code with modular structure design pattern using nWidart/laravel-modules package.

you can quickly create module using command that setup by laravel-modules package. so basically it will create separate folder for each module.

When i had started working with laravel and i see the structure of laravel 5.7 like controller, views, model, migration, console, providers and helpers etc. I was impressed and i liked more. But still i was little bit confuse, thinking we can make it modular then it become more useful and understandable. If you create module for every crud enter level like country, state, city, item, product etc. It could be fantastic because it can re-use in your other laravel application easily. Modular structure approach is good because it more useful for us.

In this post, we will create Modular structure using laravel-modules composer package. There are several other packages for create module in laravel application. laravel-modules package create “Modules” directory and sub directory module wise. it is very simple and understandable. There are listed things on that folder:

1)Config

2)Console

3)Database

4)Entites

5)Http

6)Providers

7)Routes

8)Tests

If you want to make modular your application then follow this tutorial, So first we will install laravel-modules composer package and service provider. So run bellow command for install laravel-modules package.

Setup:

Install laravel-modules Package:

composer require nwidart/laravel-modules

Publish configuration file:

php artisan vendor:publish --provider="NwidartModulesLaravelModulesServiceProvider"

Auto load file with Adding: conposer.json

{

"autoload": {

"psr-4": {

"App\": "app/",

"Modules\": "Modules/"

}

}

}

Then run following command:

composer dump-autoload

Ok, now we are ready to create module by using laravel-modules package command, So you can simply create new package as like bellow syntax:

Syntax for create module:

php artisan make:module module_name

Example for create module:

php artisan make:module Category

After run above command, you can see new migration and Modules directory on app folder. structure looks like as bellow:

app/

bootstrap/

vendor/

Modules/

├── Category/

├── Assets/

├── Config/

├── Console/

├── Database/

├── Migrations/

├── Seeders/

├── Entities/

├── Http/

├── Controllers/

├── Middleware/

├── Requests/

├── Providers/

├── CategoryServiceProvider.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

As you can see there are controllers, models, views, database, repository, routes and helper. So you can simply create more module as you require. You can simply run by following command:

php artisan serve

Open in your browser:

Also see:PHP Laravel 5.7 – Create Admin Panel Example

http://localhost:8000/category

You can get more information from here: Click Here

I hope it can help you…

Hope this code and post will helped you for implement Laravel 5.7 Modular Structure Application Example. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

Leave a Comment

Your email address will not be published. Required fields are marked *

  +  10  =  14

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US