Laravel 5.7 Modular Structure Application ExampleBy Hardik Savani | January 26, 2019 | | 5625 Viewer | Category : Laravel
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:
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.
Install laravel-modules Package:
composer require nwidart/laravel-modules
Publish configuration file:
php artisan vendor:publish --provider="Nwidart\Modules\LaravelModulesServiceProvider"
Auto load file with Adding: conposer.json
Then run following command:
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:
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:
You can get more information from here: Click Here
I hope it can help you...
- Laravel 5.7 - Stripe Payment Gateway Integration Example
- Laravel 5.7 Import Export Excel to database Example
- Laravel 5.7 - Google Recaptcha Code with Validation
- Implement Flash Message with Laravel 5.7
- Laravel 5.7 - Create REST API with authentication using Passport Tutorial
- How to send mail using queue in Laravel 5.7?
- Laravel 5.7 JQuery Form Validation Example
- Laravel 5.7 - Pagination Link Customizations Example
- Laravel 5.7 Autocomplete Search from Database using Typeahead JS
- Laravel 5.7 Ajax Pagination Example