PHPackages                             viandwi24/laravel-module-system - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. viandwi24/laravel-module-system

ActiveLibrary[Framework](/categories/framework)

viandwi24/laravel-module-system
===============================

a Module System for Laravel

445PHP

Since May 5Pushed 6y ago1 watchersCompare

[ Source](https://github.com/viandwi24/laravel-module-system)[ Packagist](https://packagist.org/packages/viandwi24/laravel-module-system)[ RSS](/packages/viandwi24-laravel-module-system/feed)WikiDiscussions master Synced 4d ago

READMEChangelogDependenciesVersions (1)Used By (0)

Laravel Module System
=====================

[](#laravel-module-system)

Add Module System to Your Laravel Application, with # Modular Application Architecture. The concept is simple, pull out the default service provider laravel and then reprogramming it to be loaded again and controlled like a Module / Plugin.

> *Specification*
>
> - Core Version : 1.0.5
> - Laravel Support : 7.x

Installation
============

[](#installation)

Add to your project with composer :

```
composer require viandwi24/laravel-module-system

```

Add service provider to your `config/app.php`

```
Viandwi24\ModuleSystem\ServiceProvider::class,

```

Add service provider to your `config/app.php`

```
'Module'  => Viandwi24\ModuleSystem\Facades\Module::class

```

and, you can publish config

```
php artisan vendor:publish --provider="Viandwi24\ModuleSystem\ServiceProvider"

```

Usage
=====

[](#usage)

Default Page
------------

[](#default-page)

We have a default page for control and management your module, Default Page can your access in `http://localhost:8000/module`. You can change default page url or disable this page with a change a config.

Config in `config/module.php` :

```
'default_page' => true,
'default_page_prefix' => 'module',
'default_page_middleware' => [],

```

Run Laravel

```
php artisan serve

```

You can access this url on browser

```
http://localhost:8000/module

```

[![Preview](https://camo.githubusercontent.com/664bea45cca007ba5ac49470cc86f5d621575de1bb6e5cff483daff8a62532ad/68747470733a2f2f692e6962622e636f2f78685958576e772f53637265656e73686f742d66726f6d2d323032302d30352d30322d30392d35362d33332e706e67)](https://camo.githubusercontent.com/664bea45cca007ba5ac49470cc86f5d621575de1bb6e5cff483daff8a62532ad/68747470733a2f2f692e6962622e636f2f78685958576e772f53637265656e73686f742d66726f6d2d323032302d30352d30322d30392d35362d33332e706e67)

For Example, you can download example module in [this link](https://github.com/viandwi24/laravel-module-system/raw/master/examples/ExampleModule.zip)Download Example Module, and then goto `http://localhost:8000/module` and click "Install .zip", upload examplemodule.zip Click, Activate in List Module

[![Preview](https://camo.githubusercontent.com/fa297dc70823fa7a96b895acbd6ae2c97ce1019291a55fd7481c4eec3c3e62cf/68747470733a2f2f692e6962622e636f2f7a726834544e332f53637265656e73686f742d66726f6d2d323032302d30352d30322d31302d30302d33322e706e67)](https://camo.githubusercontent.com/fa297dc70823fa7a96b895acbd6ae2c97ce1019291a55fd7481c4eec3c3e62cf/68747470733a2f2f692e6962622e636f2f7a726834544e332f53637265656e73686f742d66726f6d2d323032302d30352d30322d31302d30302d33322e706e67)

Finally, goto `http://localhost:8000/tes` and you see this in browser

[![Preview](https://camo.githubusercontent.com/e384a2b4a956007ecdd8d9904088ff4dee435b86378c6826b2a9443f11c05ad6/68747470733a2f2f692e6962622e636f2f3032304a7a32482f53637265656e73686f742d66726f6d2d323032302d30352d30322d31302d30322d30342e706e67)](https://camo.githubusercontent.com/e384a2b4a956007ecdd8d9904088ff4dee435b86378c6826b2a9443f11c05ad6/68747470733a2f2f692e6962622e636f2f3032304a7a32482f53637265656e73686f742d66726f6d2d323032302d30352d30322d31302d30322d30342e706e67)

Yeah, route `http://localhost:8000/tes` is a dynamic route generated from `ExampleModule`, if you disable this plugin, then when you re-access this route you will see page 404.

Module Facade
-------------

[](#module-facade)

Module class menyediakan hampir keseluruhan ungsi module, anda bisa menggunakanya dengan menggunakan :

```
Viandwi24\ModuleSystem\Facades\Module

```

### Get List Module

[](#get-list-module)

```
Module::get();

```

### Enable a Module

[](#enable-a-module)

```
Module::enable($module_name);

```

### Disable a Module

[](#disable-a-module)

```
Module::disable($module_name);

```

Make Module
===========

[](#make-module)

Module merupakan inspirasi dari Service Provider, Module yang ada memanfaatkan Service Provider bawaan laravel yang mudah anda ketahui.

```
php artisan make:module ExampleModule

```

Structure Module
================

[](#structure-module)

Module mempunyai struktur sederhana, folder Module default berada pada `app/Modules`. dimana di sebagai contoh kita telah membuat module baru `ExampleModule` di `app/Modules/ExampleModule` dengan menggunakan perintah :

```
php artisan make:module ExampleModule

```

Isi File :

- module.js
- ExampleModuleServiceProvider

modules.js
----------

[](#modulesjs)

Merupakan file konfigurasi utama sebuah module, berisi informasi :

```
{
    "name"          : "ExampleModule",
    "description"   : "Description your module",
    "version"       : "1.0",
    "author"        : "viandwi24",
    "email"         : "fiandwi0424@gmail.com",
    "web"           : "viandwi24.github.io",
    "namespace"     : "ExampleModule",
    "service"       : "ExampleModuleServiceProvider"
}

```

- namespace : namespace utama untuk module, jika dalam contoh maka namespace tersebut nantinya akan di parse menjadi `App\Modules\ExampleModule`
- service : Class utama module yang akan dieksekusi, mengikut cara kerja Service Provider bawaan laravel yang dimodifikasi.

Service Class - ExampleModuleServiceProvider.php
------------------------------------------------

[](#service-class---examplemoduleserviceproviderphp)

File ini dieksekusi layaknya Service Provider pada Laravel, berikut struktur utamanya

```
