2017 © Pedro Pelรกez
 

library modules

Laravel Modules

image

tmj/modules

Laravel Modules

  • Friday, April 14, 2017
  • by jcmlumacad
  • Repository
  • 2 Watchers
  • 0 Stars
  • 41 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 160 Forks
  • 0 Open issues
  • 56 Versions
  • 8 % Grown

The README.md

Laravel 5 Modules

tmj/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. It was forked from pingpong/modules., (*1)

Upgrade Guide

To 2.3

If you have been updated to version 2.3, please read this release note, (*2)

Your config file will looks like this., (*3)

To 2.0.18

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

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., (*5)

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., (*6)

  • 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., (*7)

Installation

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

{
    "require": {
        "tmj/modules": "^2.3"
    }
}

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)

```{r, engine='sh'} $ composer require tmj/modules, (*11)


#### Add Service Provider Next add the following service provider in `config/app.php`. ```php 'providers' => [ ... Pingpong\Modules\ModulesServiceProvider::class ],

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

'aliases' => [
    'Module' => Pingpong\Modules\Facades\Module::class,
],

Tests

Add the following directory in phpunit.xml., (*13)

    ...
    <testsuite name="Application Test Suite">
        ...
        <directory suffix="Test.php">./modules</directory>
    </testsuite>
    ...

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

```{r, engine='sh'} $ php artisan vendor:publish, (*15)


#### Autoloading By default controllers, entities or repositories not loaded automatically. You can autoload all that stuff using `psr-4`. For example : ```json { "autoload": { "psr-4": { "App\\": "app/", "Modules\\": "modules/" } } }

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.

Creating A Module

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

```{r, engine='sh'} $ php artisan module:make , (*17)


- `<module-name>` - Required. The name of module will be created. **Create a new module** ```{r, engine='sh'} $ php artisan module:make Blog

Create multiple modules, (*18)

```{r, engine='sh'} $ php artisan module:make Blog User Auth, (*19)


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. ```{r, engine='sh'} $ php artisan module:make Blog --plain

OR ```{r, engine='sh'} $ php artisan module:make Blog -p, (*20)


**Naming Convension** Because we are autoloading the modules using `psr-4`, we strongly recommend using `StudlyCase` convension. **Folder Structure**

laravel-app/ app/ bootstrap/ vendor/ modules/ โ”œโ”€โ”€ Blog/ โ”œโ”€โ”€ Assets/ โ”œโ”€โ”€ Config/ โ”œโ”€โ”€ Console/ โ”œโ”€โ”€ Database/ โ”œโ”€โ”€ Migrations/ โ”œโ”€โ”€ Seeders/ โ”œโ”€โ”€ Entities/ โ”œโ”€โ”€ Events/ โ”œโ”€โ”€ Http/ โ”œโ”€โ”€ Controllers/ โ”œโ”€โ”€ Middleware/ โ”œโ”€โ”€ Requests/ โ”œโ”€โ”€ routes.php โ”œโ”€โ”€ Interfaces/ โ”œโ”€โ”€ Jobs/ โ”œโ”€โ”€ Listeners/ โ”œโ”€โ”€ Policies/ โ”œโ”€โ”€ Providers/ โ”œโ”€โ”€ BlogServiceProvider.php โ”œโ”€โ”€ Repositories/ โ”œโ”€โ”€ Resources/ โ”œโ”€โ”€ lang/ โ”œโ”€โ”€ views/ โ”œโ”€โ”€ Repositories/ โ”œโ”€โ”€ Tests/ โ”œโ”€โ”€ composer.json โ”œโ”€โ”€ module.json โ”œโ”€โ”€ start.php, (*21)


<a name="artisan-commands"></a> ## Artisan Commands Create new module. ```{r, engine='sh'} $ php artisan module:make blog

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

```{r, engine='sh'} $ php artisan module:use blog, (*23)


Show all modules in command line. ```{r, engine='sh'} $ php artisan module:list

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

```{r, engine='sh'} $ php artisan module:make-command CustomCommand blog, (*25)

$ php artisan module:make-command CustomCommand --command=custom:command blog, (*26)

$ php artisan module:make-command CustomCommand --namespace=Modules\Blog\Commands blog, (*27)


Create new migration for the specified module. ```{r, engine='sh'} $ 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., (*28)

```{r, engine='sh'} $ php artisan module:migrate-rollback, (*29)

$ php artisan module:migrate-reset, (*30)

$ php artisan module:migrate-refresh, (*31)


Rollback, Reset and Refresh The Migrations for the specified module. ```{r, engine='sh'} $ 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)

```{r, engine='sh'} $ php artisan module:make-seed users blog, (*33)


Migrate from the specified module. ```{r, engine='sh'} $ php artisan module:migrate blog

Migrate from all modules., (*34)

```{r, engine='sh'} $ php artisan module:migrate, (*35)


Seed from the specified module. ```{r, engine='sh'} $ php artisan module:seed blog

Seed from all modules., (*36)

```{r, engine='sh'} $ php artisan module:seed, (*37)


Create new controller for the specified module. ```{r, engine='sh'} $ php artisan module:make-controller SiteController blog

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

```{r, engine='sh'} $ php artisan module:publish blog, (*39)


Publish assets from all modules to public directory. ```{r, engine='sh'} $ php artisan module:publish

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

```{r, engine='sh'} $ php artisan module:make-model User blog, (*41)

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


Create new repository for the specified module. ```{r, engine='sh'} $ php artisan module:make-repository UserRepository user

Create new policy for the specified module., (*43)

```{r, engine='sh'} $ php artisan module:make-policy UserPolicy user, (*44)


Create new event for the specified module. ```{r, engine='sh'} $ php artisan module:make-event SomeEvent user

Create new listener for the specified module, (*45)

```{r, engine='sh'} $ php artisan module:make-listener EventListener user --event=SomeEvent, (*46)


Generate the missing events and listeners for all modules based on registration ```{r, engine='sh'} $ php artisan module:event-generate

Create new job for the specified module, (*47)

```{r, engine='sh'} $ php artisan module:make-job GetUsers user, (*48)


Create new test for the specified module ```{r, engine='sh'} $ php artisan module:make-test ExampleTest user

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

```{r, engine='sh'} $ php artisan module:make-provider MyServiceProvider blog, (*50)


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. For the specified module. ```{r, engine='sh'} $ php artisan module:publish-migration blog

For all modules., (*51)

```{r, engine='sh'} $ php artisan module:publish-migration, (*52)


Enable the specified module. ```{r, engine='sh'} $ php artisan module:enable blog

Disable the specified module., (*53)

```{r, engine='sh'} $ php artisan module:disable blog, (*54)


Generate new middleware class. ```{r, engine='sh'} $ php artisan module:make-middleware Auth

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

```{r, engine='sh'} $ php artisan module:update ModuleName, (*56)


Update dependencies for all modules. ```{r, engine='sh'} $ php artisan module:update

Show the list of modules., (*57)

```{r, engine='sh'} $ php artisan module:list, (*58)


## Facades Get all modules. ```php Module::all();

Get all cached modules., (*59)

Module::getCached()

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

Module::getOrdered();

Get scanned modules., (*61)

Module::scan();

Find a specific module., (*62)

Module::find('name');

OR, (*63)

Module::get('name');

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

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

Get scanned paths., (*65)

Module::getScanPaths();

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

Module::toCollection();

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

Module::getByStatus(1);

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

Module::has('blog');

Get all enabled modules., (*69)

Module::enabled();

Get all disabled modules., (*70)

Module::disabled();

Get count of all modules., (*71)

Module::count();

Get module path., (*72)

Module::getPath();

Register the modules., (*73)

Module::register();

Boot all available modules., (*74)

Module::boot();

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

Module::collections();

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

Module::getModulePath('name');

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

Module::getAssetPath('name');

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

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

Get used storage path., (*79)

Module::getUsedStoragePath();

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

Module::getUsedNow();

OR, (*81)

Module::getUsed();

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

Module::setUsed('name');

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

Module::getAssetsPath();

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

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

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

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

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

Module::update('hello');

Module Entity

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

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

Get module name., (*88)

$module->getName();

Get module name in lowercase., (*89)

$module->getLowerName();

Get module name in studlycase., (*90)

$module->getStudlyName();

Get module path., (*91)

$module->getPath();

Get extra path., (*92)

$module->getExtraPath('Assets');

Disable the specified module., (*93)

$module->enable();

Enable the specified module., (*94)

$module->disable();

Delete the specified module., (*95)

$module->delete();

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:, (*96)

Calling Lang:, (*97)

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

Calling View:, (*98)

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

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

Calling Config:, (*99)

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., (*100)

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 :, (*101)

// file config/modules.php

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

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

{r, engine='sh'} $ php artisan module:list, (*103)

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., (*104)

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

  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

14/04 2017

dev-master

9999999-dev

Laravel Modules

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

laravel module pingpong modules hmvc

14/04 2017

v2.3.5

2.3.5.0

Laravel Modules

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

laravel module pingpong modules hmvc

14/04 2017

v2.3.4

2.3.4.0

Laravel Modules

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

laravel module pingpong modules hmvc

14/04 2017

v2.3.3

2.3.3.0

Laravel Modules

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

laravel module pingpong modules hmvc

16/02 2017

v2.3.2

2.3.2.0

Laravel Modules

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

laravel module pingpong modules hmvc

16/02 2017

v2.3

2.3.0.0

Laravel Modules

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

laravel module pingpong modules hmvc

16/02 2017

v2.3.1

2.3.1.0

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