2017 © Pedro Pelรกez
 

library modules

Laravel Modules

image

pingpong/modules

Laravel Modules

  • Thursday, September 8, 2016
  • by gravitano
  • Repository
  • 54 Watchers
  • 543 Stars
  • 110,046 Installations
  • PHP
  • 25 Dependents
  • 0 Suggesters
  • 160 Forks
  • 71 Open issues
  • 50 Versions
  • 2 % Grown

The README.md

Laravel 5 Modules

pingpong/modules is a laravel package which created to manage your large laravel app using modules. Module is like a laravel package, it have some views, controllers or models. This package is supported and tested in both Laravel 4 and Laravel 5., (*1)

, (*2)

Upgrade Guide

To 2.0.18

If you have been updated to version 2.0.18, please read this release note., (*3)

To 2.0.10

Previously, we add two service provider from this package. In version 2.0.5, we just need register one service provider. Now, we can remove Pingpong\Modules\Providers\BootstrapServiceProvider from providers array, because now it service provider is registered automatically by Pingpong\Modules\ModulesServiceProvider., (*4)

From Laravel 4 to Laravel 5

If upgrade your Laravel app from Laravel 4 to Laravel 5, there is a few things to do if you are using this package. You will receive some kind errors about config not loaded. To fix this issue, please follow this instruction., (*5)

  • If you publish the package's configuration file, you need to move the config file from app/config/packages/pingpong/modules/config.php to app/config/modules.php.
  • If you are not publish the package's configuration file and you want to publish the config file, just run php artisan vendor:publish command and you are done.

From 1.1.* to 1.2.0

New configuration file. This breaking change affected if you publish the configuration file from this package. To fix this issue, create new config file called config.php in your app/config/packages/pingpong/modules/ directory. Next move the array contents from paths.php file to paths array in new configuration file. Your config file will looks like this., (*6)

, (*7)

Installation

To install through composer, simply put the following in your composer.json file:, (*8)

{
    "require": {
        "pingpong/modules": "~2.1"
    }
}

And then run composer install to fetch the package., (*9)

Quick Installation

You could also simplify the above code by using the following command:, (*10)

composer require "pingpong/modules:~2.1"

Add Service Provider

Next add the following service provider in config/app.php., (*11)

'providers' => array(
  'Pingpong\Modules\ModulesServiceProvider',
),

Next, add the following aliases to aliases array in the same file., (*12)

'aliases' => array(
  'Module' => 'Pingpong\Modules\Facades\Module',
),

Next publish the package's configuration file by run :, (*13)

php artisan vendor:publish

Autoloading

By default controllers, entities or repositories not loaded automatically. You can autoload all that stuff using psr-4. For example :, (*14)

{
  "autoload": {
    "psr-4": {
      "App\\": "app/",
      "Modules\\": "modules/"
    }
  }
}

, (*15)

Configuration

  • modules - Used for save the generated modules.
  • assets - Used for save the modules's assets from each modules.
  • migration - Used for save the modules's migrations if you publish the modules's migrations.
  • generator - Used for generate modules folders.
  • scan - Used for allow to scan other folders.
  • enabled - If true, the package will scan other paths. By default the value is false
  • paths - The list of path which can scanned automatically by the package.
  • composer
    • vendor - Composer vendor name.
    • author.name - Composer author name.
    • author.email - Composer author email.
  • cache
    • enabled - If true, the scanned modules (all modules) will cached automatically. By default the value is false
    • key - The name of cache.
    • lifetime - Lifetime of cache.

, (*16)

Creating A Module

To create a new module you can simply run :, (*17)

php artisan module:make <module-name>
  • <module-name> - Required. The name of module will be created.

Create a new module, (*18)

php artisan module:make Blog

Create multiple modules, (*19)

php artisan module:make Blog User Auth

By default if you create a new module, that will add some resources like controller, seed class or provider automatically. If you don't want these, you can add --plain flag, to generate a plain module., (*20)

php artisan module:make Blog --plain
#OR
php artisan module:make Blog -p

Naming Convension, (*21)

Because we are autoloading the modules using psr-4, we strongly recommend using StudlyCase convension., (*22)

Folder Structure, (*23)

laravel-app/
app/
bootstrap/
vendor/
modules/
  โ”œโ”€โ”€ Blog/
      โ”œโ”€โ”€ Assets/
      โ”œโ”€โ”€ Config/
      โ”œโ”€โ”€ Console/
      โ”œโ”€โ”€ Database/
          โ”œโ”€โ”€ Migrations/
          โ”œโ”€โ”€ Seeders/
      โ”œโ”€โ”€ Entities/
      โ”œโ”€โ”€ Http/
          โ”œโ”€โ”€ Controllers/
          โ”œโ”€โ”€ Middleware/
          โ”œโ”€โ”€ Requests/
          โ”œโ”€โ”€ routes.php
      โ”œโ”€โ”€ Providers/
          โ”œโ”€โ”€ BlogServiceProvider.php
      โ”œโ”€โ”€ Resources/
          โ”œโ”€โ”€ lang/
          โ”œโ”€โ”€ views/
      โ”œโ”€โ”€ Repositories/
      โ”œโ”€โ”€ Tests/
      โ”œโ”€โ”€ composer.json
      โ”œโ”€โ”€ module.json
      โ”œโ”€โ”€ start.php

, (*24)

Artisan Commands

Create new module., (*25)

php artisan module:make blog

Use the specified module. Please see #26., (*26)

php artisan module:use blog

Show all modules in command line., (*27)

php artisan module:list

Create new command for the specified module., (*28)

php artisan module:make-command CustomCommand blog

php artisan module:make-command CustomCommand --command=custom:command blog

php artisan module:make-command CustomCommand --namespace=Modules\Blog\Commands blog

Create new migration for the specified module., (*29)

php artisan module:make-migration create_users_table blog

php artisan module:make-migration create_users_table --fields="username:string, password:string" blog

php artisan module:make-migration add_email_to_users_table --fields="email:string:unique" blog

php artisan module:make-migration remove_email_from_users_table --fields="email:string:unique" blog

php artisan module:make-migration drop_users_table blog

Rollback, Reset and Refresh The Modules Migrations., (*30)

php artisan module:migrate-rollback

php artisan module:migrate-reset

php artisan module:migrate-refresh

Rollback, Reset and Refresh The Migrations for the specified module., (*31)

php artisan module:migrate-rollback blog

php artisan module:migrate-reset blog

php artisan module:migrate-refresh blog

Create new seed for the specified module., (*32)

php artisan module:make-seed users blog

Migrate from the specified module., (*33)

php artisan module:migrate blog

Migrate from all modules., (*34)

php artisan module:migrate

Seed from the specified module., (*35)

php artisan module:seed blog

Seed from all modules., (*36)

php artisan module:seed

Create new controller for the specified module., (*37)

php artisan module:make-controller SiteController blog

Publish assets from the specified module to public directory., (*38)

php artisan module:publish blog

Publish assets from all modules to public directory., (*39)

php artisan module:publish

Create new model for the specified module., (*40)

php artisan module:make-model User blog

php artisan module:make-model User blog --fillable="username,email,password"

Create new service provider for the specified module., (*41)

php artisan module:make-provider MyServiceProvider blog

Publish migration for the specified module or for all modules. This helpful when you want to rollback the migrations. You can also run php artisan migrate instead of php artisan module:migrate command for migrate the migrations., (*42)

For the specified module., (*43)

php artisan module:publish-migration blog

For all modules., (*44)

php artisan module:publish-migration

Enable the specified module., (*45)

php artisan module:enable blog

Disable the specified module., (*46)

php artisan module:disable blog

Generate new middleware class., (*47)

php artisan module:make-middleware Auth

Update dependencies for the specified module., (*48)

php artisan module:update ModuleName

Update dependencies for all modules., (*49)

php artisan module:update

Show the list of modules., (*50)

php artisan module:list

, (*51)

Facades

Get all modules., (*52)

Module::all();

Get all cached modules., (*53)

Module::getCached()

Get ordered modules. The modules will be ordered by the priority key in module.json file., (*54)

Module::getOrdered();

Get scanned modules., (*55)

Module::scan();

Find a specific module., (*56)

Module::find('name');
// OR
Module::get('name');

Find a module, if there is one, return the Module instance, otherwise throw Pingpong\Modules\Exeptions\ModuleNotFoundException., (*57)

Module::findOrFail('module-name');

Get scanned paths., (*58)

Module::getScanPaths();

Get all modules as a collection instance., (*59)

Module::toCollection();

Get modules by the status. 1 for active and 0 for inactive., (*60)

Module::getByStatus(1);

Check the specified module. If it exists, will return true, otherwise false., (*61)

Module::has('blog');

Get all enabled modules., (*62)

Module::enabled();

Get all disabled modules., (*63)

Module::disabled();

Get count of all modules., (*64)

Module::count();

Get module path., (*65)

Module::getPath();

Register the modules., (*66)

Module::register();

Boot all available modules., (*67)

Module::boot();

Get all enabled modules as collection instance., (*68)

Module::collections();

Get module path from the specified module., (*69)

Module::getModulePath('name');

Get assets path from the specified module., (*70)

Module::getAssetPath('name');

Get config value from this package., (*71)

Module::config('composer.vendor');

Get used storage path., (*72)

Module::getUsedStoragePath();

Get used module for cli session., (*73)

Module::getUsedNow();
// OR
Module::getUsed();

Set used module for cli session., (*74)

Module::setUsed('name');

Get modules's assets path., (*75)

Module::getAssetsPath();

Get asset url from specific module., (*76)

Module::asset('blog:img/logo.img');

Install the specified module by given module name., (*77)

Module::install('pingpong-modules/hello');

Update dependencies for the specified module., (*78)

Module::update('hello');

, (*79)

Module Entity

Get an entity from a specific module., (*80)

$module = Module::find('blog');

Get module name., (*81)

$module->getName();

Get module name in lowercase., (*82)

$module->getLowerName();

Get module name in studlycase., (*83)

$module->getStudlyName();

Get module path., (*84)

$module->getPath();

Get extra path., (*85)

$module->getExtraPath('Assets');

Disable the specified module., (*86)

$module->enable();

Enable the specified module., (*87)

$module->disable();

Delete the specified module., (*88)

$module->delete();

, (*89)

Custom Namespaces

When you create a new module it also registers new custom namespace for Lang, View and Config. For example, if you create a new module named blog, it will also register new namespace/hint blog for that module. Then, you can use that namespace for calling Lang, View or Config. Following are some examples of its usage:, (*90)

Calling Lang:, (*91)

Lang::get('blog::group.name');

Calling View:, (*92)

View::make('blog::index')

View::make('blog::partials.sidebar')

Calling Config:, (*93)

Config::get('blog.name')

Publishing Modules

Have you created a laravel modules? Yes, I've. Then, I want to publish my modules. Where do I publish it? That's the question. What's the answer ? The answer is Packagist. In pingpong/modules version >= 1.2.0, when you generate a module, you will see there is a new file generated called composer.json., (*94)

, (*95)

Auto Scan Vendor Directory

By default the vendor directory is not scanned automatically, you need to update the configuration file to allow that. Set scan.enabled value to true. For example :, (*96)

// file config/modules.php

return [
  //...
  'scan' => [
    'enabled' => true
  ]
  //...
]

You can verify the module has been installed using module:list command:, (*97)

php artisan module:list

, (*98)

Publishing Modules

After creating a module and you are sure your module module will be used by other developers. You can push your module to github or bitbucket and after that you can submit your module to the packagist website., (*99)

You can follow this step to publish your module., (*100)

  1. Create A Module.
  2. Push the module to github.
  3. Submit your module to the packagist website. Submit to packagist is very easy, just give your github repository, click submit and you done.

The Versions

08/09 2016

dev-master

9999999-dev

Laravel Modules

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

laravel module pingpong modules hmvc

08/09 2016

2.2.x-dev

2.2.9999999.9999999-dev

Laravel Modules

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

laravel module pingpong modules hmvc

11/01 2016

v2.2.0

2.2.0.0

Laravel Modules

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

laravel module pingpong modules hmvc

23/12 2015

2.1.x-dev

2.1.9999999.9999999-dev

Laravel Modules

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

laravel module pingpong modules hmvc

23/12 2015

v2.1.6

2.1.6.0

Laravel Modules

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

laravel module pingpong modules hmvc

06/11 2015

v2.1.5

2.1.5.0

Laravel Modules

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

laravel module pingpong modules hmvc

30/06 2015

v2.1.4

2.1.4.0

Laravel Modules

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

laravel module pingpong modules hmvc

27/06 2015

v2.1.0

2.1.0.0

Laravel Modules

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

laravel module pingpong modules hmvc

22/06 2015

2.0.x-dev

2.0.9999999.9999999-dev

Laravel Modules

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

laravel module pingpong modules hmvc

22/06 2015

2.0.21

2.0.21.0

Laravel Modules

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

laravel module pingpong modules hmvc

11/06 2015

2.0.18

2.0.18.0

Laravel Modules

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

laravel module pingpong modules hmvc

09/06 2015

2.0.17

2.0.17.0

Laravel Modules

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

laravel module pingpong modules hmvc

08/06 2015

2.0.14

2.0.14.0

Laravel Modules

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

laravel module pingpong modules hmvc

07/06 2015

2.0.13

2.0.13.0

Laravel Modules

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

laravel module pingpong modules hmvc

06/06 2015

2.0.12

2.0.12.0

Laravel Modules

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

laravel module pingpong modules hmvc

05/06 2015

2.0.11

2.0.11.0

Laravel Modules

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

laravel module pingpong modules hmvc

05/06 2015

2.0.10

2.0.10.0

Laravel Modules

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

laravel module pingpong modules hmvc

22/05 2015

2.0.8

2.0.8.0

Laravel Modules

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

laravel module pingpong modules hmvc

21/05 2015

2.0.7

2.0.7.0

Laravel Modules

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

laravel module pingpong modules hmvc

19/05 2015

2.0.6

2.0.6.0

Laravel Modules

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

laravel module pingpong modules hmvc

17/05 2015

2.0.4

2.0.4.0

Laravel Modules

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

laravel module pingpong modules hmvc

12/05 2015

2.0.2

2.0.2.0

Laravel Modules

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

laravel module pingpong modules hmvc

08/05 2015

2.0.0

2.0.0.0

Laravel Modules

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

laravel module pingpong modules hmvc

05/02 2015

1.0.x-dev

1.0.9999999.9999999-dev

Laravel Modules

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

laravel module pingpong modules hmvc

24/12 2014

1.2.1

1.2.1.0

Laravel Modules

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

laravel module pingpong modules hmvc

20/12 2014

1.2.0

1.2.0.0

Laravel Modules

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

laravel module pingpong modules hmvc

04/12 2014

1.1.11

1.1.11.0

Laravel Modules

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

laravel module pingpong modules hmvc

28/11 2014

1.1.10

1.1.10.0

Laravel Modules

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

laravel module pingpong modules hmvc

27/11 2014

1.1.9

1.1.9.0

Laravel Modules

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

laravel module pingpong modules hmvc

26/11 2014

1.1.8

1.1.8.0

Laravel Modules

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

laravel module pingpong modules hmvc

22/11 2014

1.1.7

1.1.7.0

Laravel Modules

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

laravel module pingpong modules hmvc

20/07 2014

1.0.7

1.0.7.0

Laravel 4 - Simple Modules

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel simple pingpong modules hmvc

27/06 2014

1.0.6

1.0.6.0

Laravel 4 - Simple Modules

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel simple pingpong modules hmvc

24/06 2014

1.0.5

1.0.5.0

Laravel 4 - Simple Modules

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel simple pingpong modules hmvc

23/04 2014

1.0.4

1.0.4.0

Laravel 4 - Simple Modules

  Sources   Download

MIT

The Requires

 

laravel simple pingpong modules hmvc

05/04 2014

1.0.3

1.0.3.0

Laravel 4 - Simple Modules

  Sources   Download

MIT

The Requires

 

laravel simple pingpong modules hmvc

03/04 2014

1.0.2

1.0.2.0

Laravel 4 - Simple Modules

  Sources   Download

MIT

The Requires

 

laravel simple pingpong modules hmvc

03/04 2014

1.0.1

1.0.1.0

Laravel 4 - Simple Modules

  Sources   Download

MIT

The Requires

 

laravel simple pingpong modules hmvc

19/02 2014

1.0.0

1.0.0.0

This package makes laravel can implement HMVC or modular. With this package, you can create a web application that is structured and easier to manage a large web application.

  Sources   Download

The MIT License (MIT)

The Requires

  • php >=5.3.0

 

The Development Requires

laravel pingpong modules hmvc modular laravel-modular laravel-modules