PHPackages                             megaads/clara-app-store - 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. megaads/clara-app-store

ActiveLibrary[Framework](/categories/framework)

megaads/clara-app-store
=======================

Module management in Laravel

1.1.23(4y ago)0215↓100%MITPHPPHP &gt;=5.6.4CI failing

Since Aug 13Pushed 4y ago5 watchersCompare

[ Source](https://github.com/megaads-vn/clara-app-store)[ Packagist](https://packagist.org/packages/megaads/clara-app-store)[ Docs](https://www.megaads.vn)[ RSS](/packages/megaads-clara-app-store/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (4)Versions (26)Used By (0)

Clara
=====

[](#clara)

A module management in Laravel

System requirements
-------------------

[](#system-requirements)

- PHP: &gt;=5.6
- Laravel Framework: &gt;=5.4

Installation
------------

[](#installation)

Clara is packed as a composer package. So it can be installed quickly:

1. Require the composer package

    `composer require megaads/clara`
2. Register the provider:

    `Megaads\Clara\Providers\ModuleServiceProvider`
3. Register the facade:

    `Megaads\Clara\Facades\ModuleFacade`
4. Autoloading

By default the module classes are not loaded automatically. You can autoload your modules in composer.json

```
{
    "autoload": {
        "psr-4": {
            "App\\": "app/",
            "Modules\\": "app/Modules"
        }
    },
    "extra": {
        "merge-plugin": {
            "include": [
                "app/Modules/*/module.json"
            ]
        }
    }
}
```

5. Publish file config

With the module submit function, must have url configuration of store. To generate clara configuration file:

```
php artisan vendor:publish --provider="Megaads\Clara\Providers\ModuleServiceProvider"

```

Module Management
-----------------

[](#module-management)

### Create module

[](#create-module)

```
php artisan module:make  ...

```

Folder structure

```
app
│
└───Modules

    └───ModuleName
        │
        └───Config
        │      app.php
        │
        └───Controllers
        │      Controller.php
        │      ...
        │
        └───Helpers
        │      helper.php
        │      ...
        │
        └───Middlewares
        │      ExampleMiddleware.php
        │      ...
        │
        └───Models
        │      ...
        │
        └───Resources
        │      Views
        │      Assets
        │      ...
        │
        └───Routes
        │      routes.php
        │      ...
        │
        └───Kernel.php
        │
        └───module.json
        │
        └───start.php

```

- module.json: the module configuration file is based on composer composer.json. All configurations in the module.json will be merged to main composer.json.
- start.php: the module's start file that will be loaded every requests. So module actions, module views... can be registered in this file.

### Install module from a file or an URL

[](#install-module-from-a-file-or-an-url)

```
php artisan module:install   ...

```

### Enable module

[](#enable-module)

```
php artisan module:enable  ...

```

### Disable module

[](#disable-module)

```
php artisan module:disable  ...

```

### Remove module

[](#remove-module)

```
php artisan module:remove  ...

```

### Remove all modules

[](#remove-all-modules)

```
php artisan module:remove-all

```

Module Action
-------------

[](#module-action)

### Fire a action

[](#fire-a-action)

Using PHP

```
Module::action('action_name', [params]);
```

Using blade statement

```
@action('action_name', [params])
```

### Handle a action

[](#handle-a-action)

```
Module::onAction('action_name', function ($params) {

}, PRIORITY);
```

Handle a action using a controller

```
Module::onAction('action_name', 'Modules\Example\Controllers\HomeController@action', PRIORITY);
```

By default, Clara supplies actions:

- module\_made
- module\_loaded
- module\_disabled
- module\_enabled
- module\_removed
- module\_removed\_all

Module View
-----------

[](#module-view)

### Register a view

[](#register-a-view)

Using PHP

```
Module::view('view_name', [params], IS_MULTI_LAYER);
```

```
Module::view('view_name', 'This is a view placeholder', IS_MULTI_LAYER);
```

```
Module::view('view_name', function() {
    return 'This is a view placeholder';
}, IS_MULTI_LAYER);
```

Using blade statement

```
@view('view_name', [params])
```

### Handle a view

[](#handle-a-view)

```
Module::onView('view_name', function ($params) {
    return view('module-namespace:home.index');
}, PRIORITY);
```

Handle a view using a controller

```
Module::onView('view_name', 'Modules\Example\Controllers\HomeController@index', PRIORITY);
```

Module variable
---------------

[](#module-variable)

### Register a variable

[](#register-a-variable)

Using PHP

```
$variable = Module::variable('handle', $default, PRIORITY);
```

Using blade statement

```
@variable('variable_name', 'handle', $default);
```

### Handle a variable

[](#handle-a-variable)

```
Module::onVariable('hanlde', function ($params) {
}, PRIORITY, NUUM_OF_PARAM);
```

Module Assets
-------------

[](#module-assets)

Clara will create a symbol link from module asset directory `app/Modules/{ModuleName}/Resources/Assets` to `public/modules/{ModuleNamespace}`

### Include a module asset

[](#include-a-module-asset)

Using PHP

```
